Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Created February 8, 2025 15:00
Show Gist options
  • Save jdmichaud/e4acd50f66892e62208d80cf7528a3ea to your computer and use it in GitHub Desktop.
Save jdmichaud/e4acd50f66892e62208d80cf7528a3ea to your computer and use it in GitHub Desktop.
Jenkins hash
// Broken implementation
function hash(s) {
let hash = new Uint32Array(1);
hash[0] = 0;
for (let i = 0; i < s.length; ++i) {
const c = s[i].charCodeAt(0);
hash[0] += c;
hash[0] += (hash[0] << 10);
hash[0] ^= (hash[0] >> 6);
}
hash[0] += (hash[0] << 3);
hash[0] ^= (hash[0] >> 11);
hash[0] += (hash[0] << 15);
return hash[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment