-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathcaml_hash_primitive.js
51 lines (44 loc) · 1.27 KB
/
caml_hash_primitive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function rotl32(x, n) {
return (x << n) | (x >>> (32 - n | 0)) | 0;
}
function hash_mix_int(h, d) {
let d$1 = d;
d$1 = Math.imul(d$1, -862048943);
d$1 = rotl32(d$1, 15);
d$1 = Math.imul(d$1, 461845907);
let h$1 = h ^ d$1;
h$1 = rotl32(h$1, 13);
return (h$1 + (h$1 << 2) | 0) - 430675100 | 0;
}
function hash_final_mix(h) {
let h$1 = h ^ (h >>> 16);
h$1 = Math.imul(h$1, -2048144789);
h$1 = h$1 ^ (h$1 >>> 13);
h$1 = Math.imul(h$1, -1028477387);
return h$1 ^ (h$1 >>> 16);
}
function hash_mix_string(h, s) {
let len = s.length;
let block = (len / 4 | 0) - 1 | 0;
let hash = h;
for (let i = 0; i <= block; ++i) {
let j = (i << 2);
let w = s.charCodeAt(j) | (s.charCodeAt(j + 1 | 0) << 8) | (s.charCodeAt(j + 2 | 0) << 16) | (s.charCodeAt(j + 3 | 0) << 24);
hash = hash_mix_int(hash, w);
}
let modulo = len & 3;
if (modulo !== 0) {
let w$1 = modulo === 3 ? (s.charCodeAt(len - 1 | 0) << 16) | (s.charCodeAt(len - 2 | 0) << 8) | s.charCodeAt(len - 3 | 0) : (
modulo === 2 ? (s.charCodeAt(len - 1 | 0) << 8) | s.charCodeAt(len - 2 | 0) : s.charCodeAt(len - 1 | 0)
);
hash = hash_mix_int(hash, w$1);
}
hash = hash ^ len;
return hash;
}
export {
hash_mix_int,
hash_mix_string,
hash_final_mix,
}
/* No side effect */