-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfc.js
41 lines (34 loc) · 1.09 KB
/
sfc.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
function sfc32(a, b, c, d) {
return function() {
a |= 0; b |= 0; c |= 0; d |= 0;
var t = (a + b | 0) + d | 0;
d = d + 1 | 0;
a = b ^ b >>> 9;
b = c + (c << 3) | 0;
c = c << 21 | c >>> 11;
c = c + t | 0;
return (t >>> 0) / 4294967296;
}
}
function MurmurHash3(key, seed = 0) {
var k, p1 = 3432918353, p2 = 461845907, h = seed | 0;
for(var i = 0, b = key.length & -4; i < b; i += 4) {
k = key[i+3] << 24 | key[i+2] << 16 | key[i+1] << 8 | key[i];
k = Math.imul(k, p1); k = k << 15 | k >>> 17;
h ^= Math.imul(k, p2); h = h << 13 | h >>> 19;
h = Math.imul(h, 5) + 3864292196 | 0; // |0 = prevent float
}
k = 0;
switch (key.length & 3) {
case 3: k ^= key[i+2] << 16;
case 2: k ^= key[i+1] << 8;
case 1: k ^= key[i];
k = Math.imul(k, p1); k = k << 15 | k >>> 17;
h ^= Math.imul(k, p2);
}
h ^= key.length;
h ^= h >>> 16; h = Math.imul(h, 2246822507);
h ^= h >>> 13; h = Math.imul(h, 3266489909);
h ^= h >>> 16;
return h >>> 0;
}