Skip to content

Instantly share code, notes, and snippets.

@lichenbo
Created July 14, 2013 06:59
Show Gist options
  • Save lichenbo/5993454 to your computer and use it in GitHub Desktop.
Save lichenbo/5993454 to your computer and use it in GitHub Desktop.
static int hash(int h) {
// This function ensures that hashCodes that differ only by
// constant multiples at each bit position have a bounded
// number of collisions (approximately 8 at default load factor).
h ^= (h >>> 20) ^ (h >>> 12);
return h ^ (h >>> 7) ^ (h >>> 4);
}
static int indexFor(int h, int length) {
return h & (length-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment