-
-
Save Vulcanacht/3567b0daabf5c9c57613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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