Search in sources :

Example 6 with IntHashTable

use of com.ociweb.pronghorn.pipe.util.hash.IntHashTable in project PronghornPipes by oci-pronghorn.

the class StructRegistry method addStruct.

/**
 * Add new Structure to the schema
 * @param fieldNames - name for each field
 * @param fieldTypes - type for each field
 * @param fieldDim - dominations for this field, should be 0 for most cases of simple data
 * @return the array of field identifiers in the same order as defined
 */
public int addStruct(byte[][] fieldNames, // all fields are precede by array count byte
StructTypes[] fieldTypes, // Dimensionality, should be 0 for simple objects.
int[] fieldDim, Object[] fieldAssoc) {
    assert (fieldNames.length == fieldTypes.length);
    if (null != fieldDim) {
        assert (fieldNames.length == fieldDim.length);
        maxDims(fieldDim);
    }
    int structIdx = structCount++;
    grow(structCount);
    int n = fieldNames.length;
    boolean skipDeepChecks = false;
    boolean supportsExtraction = false;
    boolean ignoreCase = true;
    TrieParser fieldParser = new TrieParser(n * 20, 4, skipDeepChecks, supportsExtraction, ignoreCase);
    long base = ((long) (IS_STRUCT_BIT | (STRUCT_MASK & structIdx))) << STRUCT_OFFSET;
    while (--n >= 0) {
        assert (isNotAlreadyDefined(fieldParser, fieldNames[n]));
        // bad value..
        fieldParser.setValue(fieldNames[n], base | n);
    }
    this.fields[structIdx] = fieldParser;
    this.fieldNames[structIdx] = fieldNames;
    this.fieldTypes[structIdx] = fieldTypes;
    this.fieldDims[structIdx] = null == fieldDim ? new int[fieldTypes.length] : fieldDim;
    this.fieldLocals[structIdx] = new Object[fieldNames.length];
    this.fieldAttachedIndex[structIdx] = new IntHashTable(IntHashTable.computeBits(Math.max(fieldNames.length, 8) * 3));
    if (null != fieldAssoc) {
        int j = fieldAssoc.length;
        while (--j >= 0) {
            if (null != fieldAssoc[j]) {
                setAssoc(fieldAssoc[j], structIdx, j);
            }
        }
    }
    return structIdx | IS_STRUCT_BIT;
}
Also used : IntHashTable(com.ociweb.pronghorn.pipe.util.hash.IntHashTable) TrieParser(com.ociweb.pronghorn.util.TrieParser)

Example 7 with IntHashTable

use of com.ociweb.pronghorn.pipe.util.hash.IntHashTable in project PronghornPipes by oci-pronghorn.

the class IntHashTableTest method addToHashTableThenReplace.

@Test
public void addToHashTableThenReplace() {
    int testBits = 9;
    int testSize = (1 << testBits);
    int extra = testSize + 1;
    IntHashTable ht = new IntHashTable(testBits);
    int j = testSize;
    while (--j > 0) {
        assertTrue(IntHashTable.setItem(ht, j, j * 7));
    }
    // out of space
    assertFalse(IntHashTable.setItem(ht, extra, extra * 7));
    j = testSize;
    while (--j > 0) {
        assertTrue(IntHashTable.replaceItem(ht, j, j * 13));
    }
    j = testSize;
    while (--j > 0) {
        assertTrue(IntHashTable.hasItem(ht, j));
        assertTrue(0 != IntHashTable.getItem(ht, j));
        assertEquals("at position " + j, j * 13, IntHashTable.getItem(ht, j));
    }
}
Also used : IntHashTable(com.ociweb.pronghorn.pipe.util.hash.IntHashTable) Test(org.junit.Test)

Aggregations

IntHashTable (com.ociweb.pronghorn.pipe.util.hash.IntHashTable)7 Test (org.junit.Test)3 TrieParser (com.ociweb.pronghorn.util.TrieParser)2 TrafficAckSchema (com.ociweb.gl.impl.schema.TrafficAckSchema)1 TrafficReleaseSchema (com.ociweb.gl.impl.schema.TrafficReleaseSchema)1 Pipe (com.ociweb.pronghorn.pipe.Pipe)1 GraphManager (com.ociweb.pronghorn.stage.scheduling.GraphManager)1 TrieParserReader (com.ociweb.pronghorn.util.TrieParserReader)1