Last active
May 29, 2021 22:03
-
-
Save thierryc/30ed60264ea68bce5c168bb6014e909e to your computer and use it in GitHub Desktop.
Javascript Jenkins's one-at-a-time hash function
This file contains hidden or 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
// 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