private int addName(String name, int q1, int q2, int q3) { final int index = _count; int offset = _findOffsetForAdd(calcHash(q1, q2, q3)); _hashArea[offset] = q1; _hashArea[offset+1] = q2; _hashArea[offset+2] = q3; _hashArea[offset+3] = _lengthAndIndex(3); // increases _count return index; }
private int addName(String name, int q1, int q2) { final int index = _count; int offset = _findOffsetForAdd(calcHash(q1, q2)); _hashArea[offset] = q1; _hashArea[offset+1] = q2; _hashArea[offset+3] = _lengthAndIndex(2); // increases _count return index; }
private int addName(String name, int q1) { final int index = _count; int offset = _findOffsetForAdd(calcHash(q1)); _hashArea[offset] = q1; _hashArea[offset+3] = _lengthAndIndex(1); // increases _count return index; }
@Override public int matchByQuad(int q1, int q2) { int offset = _calcOffset(calcHash(q1, q2)); final int[] hashArea = _hashArea; int lenAndIndex = hashArea[offset+3]; if ((lenAndIndex & 0xFFFF) == 2) { if ((q1 == hashArea[offset]) && (q2 == hashArea[offset+1])) { return lenAndIndex >> 16; } } else if (lenAndIndex == 0) { // empty slot; unlikely but avoid further lookups if so return -1; } // secondary? int offset2 = _secondaryStart + ((offset >> 3) << 2); int lenAndIndex2 = hashArea[offset2+3]; if ((lenAndIndex2 & 0xFFFF) == 2) { if ((q1 == hashArea[offset2]) && (q2 == hashArea[offset2+1])) { return lenAndIndex2 >> 16; } } else if (lenAndIndex2 == 0) { // empty slot? Short-circuit if no more spillovers return -1; } return _findTertiary(offset, q1, q2); }
@Override public int matchByQuad(int q1, int q2, int q3) { int offset = _calcOffset(calcHash(q1, q2, q3)); final int[] hashArea = _hashArea; final int lenAndIndex = hashArea[offset+3]; if ((lenAndIndex & 0xFFFF) == 3) { if ((q1 == hashArea[offset]) && (hashArea[offset+1] == q2) && (hashArea[offset+2] == q3)) { return lenAndIndex >> 16; } } else if (lenAndIndex == 0) { // empty slot; unlikely but avoid further lookups if so return -1; } // secondary? int offset2 = _secondaryStart + ((offset >> 3) << 2); final int lenAndIndex2 = hashArea[offset2+3]; if ((lenAndIndex2 & 0xFFFF) == 3) { if ((q1 == hashArea[offset2]) && (hashArea[offset2+1] == q2) && (hashArea[offset2+2] == q3)) { return lenAndIndex2 >> 16; } } else if (lenAndIndex2 == 0) { // empty slot? Short-circuit if no more spillovers return -1; } return _findTertiary(offset, q1, q2, q3); }
@Override public int matchByQuad(int q1) { int offset = _calcOffset(calcHash(q1)); // first: primary match? final int[] hashArea = _hashArea; int lenAndIndex = hashArea[offset+3]; if ((lenAndIndex & 0xFFFF) == 1) { if (hashArea[offset] == q1) { return lenAndIndex >> 16; } } else if (lenAndIndex == 0) { // empty slot; unlikely but avoid further lookups if so return -1; } // secondary? single slot shared by N/2 primaries int offset2 = _secondaryStart + ((offset >> 3) << 2); lenAndIndex = hashArea[offset2+3]; if ((lenAndIndex & 0xFFFF) == 1) { if (hashArea[offset2] == q1) { return lenAndIndex >> 16; } } else if (lenAndIndex == 0) { // empty slot; unlikely but avoid further lookups if so return -1; } // tertiary lookup & spillovers best to offline return _findTertiary(offset, q1); }
private int addName(String name, int[] q, int qlen) { switch (qlen) { case 1: return addName(name, q[0]); case 2: return addName(name, q[0], q[1]); case 3: return addName(name, q[0], q[1], q[2]); } final int index = _count; final int hash = calcHash(q, qlen); int offset = _findOffsetForAdd(hash); _hashArea[offset] = hash; int longStart = _appendLongName(q, qlen); _hashArea[offset+1] = longStart; _hashArea[offset+3] = _lengthAndIndex(qlen); // increases _count return index; }
final int hash = calcHash(q, qlen); int offset = _calcOffset(hash);