Skip to content

Instantly share code, notes, and snippets.

@Vulcanacht
Created November 28, 2015 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vulcanacht/3567b0daabf5c9c57613 to your computer and use it in GitHub Desktop.
Save Vulcanacht/3567b0daabf5c9c57613 to your computer and use it in GitHub Desktop.
package com.jagex.runetek4.js5;
public class NameHashTable {
private int[] table;
public NameHashTable(final int[] src) {
int size;
for (size = 1; size <= (src.length + (src.length >> 1)); size <<= 1) {
}
this.table = new int[size + size];
for (int index = 0; index < (size + size); index++) {
this.table[index] = -1;
}
int offset = 0;
while (offset < src.length) {
int pos;
for (pos = src[offset] & (size - 1); this.table[pos + pos + 1] != -1; pos = (pos + 1) & (size - 1)) {
}
this.table[pos + pos] = src[offset];
this.table[pos + pos + 1] = offset++;
}
}
public int lookup(final int hash) {
final int size = (this.table.length >> 1) - 1;
int position = hash & size;
for (; ; ) {
final int current = this.table[position + position + 1];
if (current == -1) {
return -1;
}
if (this.table[position + position] == hash) {
return current;
}
position = (position + 1) & size;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment