Skip to content

Instantly share code, notes, and snippets.

@thierryc
Last active May 29, 2021 22:03
Show Gist options
  • Save thierryc/30ed60264ea68bce5c168bb6014e909e to your computer and use it in GitHub Desktop.
Save thierryc/30ed60264ea68bce5c168bb6014e909e to your computer and use it in GitHub Desktop.
Javascript Jenkins's one-at-a-time hash function
// An implementation of Jenkins's one-at-a-time hash
// <http://en.wikipedia.org/wiki/Jenkins_hash_function>
// key: string
// return hex
function oneAtATimeHash(key) {
var hash = 0, i = key.length;
while (i--) {
hash += key.charCodeAt(i);
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return hash.toString(16);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment