From 6efa624e42b04277437b42a7bd46a7c077f49ae3 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Thu, 6 Sep 2018 12:00:29 -0700 Subject: [PATCH] add hashFnv32a for array of 32 bit numbers --- src/mol-data/util/hash-functions.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mol-data/util/hash-functions.ts b/src/mol-data/util/hash-functions.ts index d822d8d9c..001eaf5e1 100644 --- a/src/mol-data/util/hash-functions.ts +++ b/src/mol-data/util/hash-functions.ts @@ -67,4 +67,16 @@ export function cantorPairing(a: number, b: number) { */ export function sortedCantorPairing(a: number, b: number) { 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 -- GitLab