Created
February 8, 2025 15:00
-
-
Save jdmichaud/e4acd50f66892e62208d80cf7528a3ea to your computer and use it in GitHub Desktop.
Jenkins hash
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
// 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