Skip to content
Snippets Groups Projects
Commit 6efa624e authored by Alexander Rose's avatar Alexander Rose
Browse files

add hashFnv32a for array of 32 bit numbers

parent 91a3197d
No related branches found
No related tags found
No related merge requests found
...@@ -67,4 +67,16 @@ export function cantorPairing(a: number, b: number) { ...@@ -67,4 +67,16 @@ export function cantorPairing(a: number, b: number) {
*/ */
export function sortedCantorPairing(a: number, b: number) { export function sortedCantorPairing(a: number, b: number) {
return a < b ? cantorPairing(a, b) : cantorPairing(b, a); return a < b ? cantorPairing(a, b) : cantorPairing(b, a);
}
/**
* 32 bit FNV-1a hash, see http://isthe.com/chongo/tech/comp/fnv/
*/
export function hashFnv32a(array: number[]) {
let hval = 0x811c9dc5;
for (let i = 0, il = array.length; i < il; ++i) {
hval ^= array[i];
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
}
return hval >>> 0;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment