Skip to content

Instantly share code, notes, and snippets.

@ahmetaa
Created October 12, 2018 12:03
Show Gist options
  • Save ahmetaa/cd056c458411a112f653ec4755f830a3 to your computer and use it in GitHub Desktop.
Save ahmetaa/cd056c458411a112f653ec4755f830a3 to your computer and use it in GitHub Desktop.
hash locate
protected int locate(int key) {
int slot = hash(key) & modulo;
int pointer = -1;
while (true) {
final int k = keys[slot];
if (k == EMPTY) {
return pointer < 0 ? (-slot - 1) : (-pointer - 1);
}
if (k == DELETED) {
if (pointer < 0) {
pointer = slot;
}
slot = (slot + 1) & modulo;
continue;
}
if (k == key) {
return slot;
}
slot = (slot + 1) & modulo;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment