Skip to content

Instantly share code, notes, and snippets.

@zhenchuan
Last active August 29, 2015 13:56
Show Gist options
  • Save zhenchuan/ac33042b68f4b01733da to your computer and use it in GitHub Desktop.
Save zhenchuan/ac33042b68f4b01733da to your computer and use it in GitHub Desktop.
IndexHash.java#L275
boolean isAt(int keyLen, byte[] key, long position, int entryIndex) throws IOException {
HashType hashData = header.getHashType();
AddressSize addressData = header.getAddressData();
long hash = hashData.hash(keyLen, key, hashSeed);
long wantedSlot = getWantedSlot(hash, hashCapacity);
int start = indexStart;
long pos = start + wantedSlot * slotSize;
indexData.seek(pos);
long slot = wantedSlot;
long displacement = 0;
while (true) {
long hash2 = hashData.readHash(indexData);
long position2 = addressData.readAddress(indexData);
if (position2 == 0) {
return false;
}
int entryIndex2 = (int) (position2) & entryBlockBitmask;
position2 >>>= entryBlockBits;
if (hash == hash2 && position2 == position && entryIndex == entryIndex2) {
return true;
}
long otherDisplacement = getDisplacement(hashCapacity, slot, hash2);
if (displacement > otherDisplacement) {
return false;
}
displacement ++ ; //here!
pos += slotSize;
slot++;
if (slot == hashCapacity) {
pos = start;
slot = 0;
indexData.seek(start);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment