Created
May 16, 2019 20:58
-
-
Save di3/d3f517228853679d7ea9d7f7ff956704 to your computer and use it in GitHub Desktop.
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
const FNV_OFFSET_32 = 0x811c9dc5; | |
export const hash_fnv32a (input) => { | |
let hval = FNV_OFFSET_32; | |
// Strips unicode bits, only the lower 8 bits of the values are used | |
for (var i = 0; i < input.length; i++) { | |
hval = hval ^ (input.charCodeAt(i) & 0xFF); | |
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24); | |
} | |
return hval >>> 0; | |
} | |
//assert.equal(hash_fnv32a('aaaa'), 1290481081); | |
//assert.equal(hash_fnv32a(123456), 2166136261); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment