Skip to content

Instantly share code, notes, and snippets.

@atdt
Created April 7, 2012 17:28
Show Gist options
  • Save atdt/2330641 to your computer and use it in GitHub Desktop.
Save atdt/2330641 to your computer and use it in GitHub Desktop.
An implementation of Jenkins's one-at-a-time hash
// An implementation of Jenkins's one-at-a-time hash
// <http://en.wikipedia.org/wiki/Jenkins_hash_function>
function hashString(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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment