-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathfp.js
More file actions
223 lines (218 loc) · 7.5 KB
/
fp.js
File metadata and controls
223 lines (218 loc) · 7.5 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/// MurmurHash3 related functions
//
// Given two 64bit ints (as an array of two 32bit ints) returns the two
// added together as a 64bit int (as an array of two 32bit ints).
//
var x64Add = function (m, n) {
m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff]
n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff]
var o = [0, 0, 0, 0]
o[3] += m[3] + n[3]
o[2] += o[3] >>> 16
o[3] &= 0xffff
o[2] += m[2] + n[2]
o[1] += o[2] >>> 16
o[2] &= 0xffff
o[1] += m[1] + n[1]
o[0] += o[1] >>> 16
o[1] &= 0xffff
o[0] += m[0] + n[0]
o[0] &= 0xffff
return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]]
}
//
// Given two 64bit ints (as an array of two 32bit ints) returns the two
// multiplied together as a 64bit int (as an array of two 32bit ints).
//
var x64Multiply = function (m, n) {
m = [m[0] >>> 16, m[0] & 0xffff, m[1] >>> 16, m[1] & 0xffff]
n = [n[0] >>> 16, n[0] & 0xffff, n[1] >>> 16, n[1] & 0xffff]
var o = [0, 0, 0, 0]
o[3] += m[3] * n[3]
o[2] += o[3] >>> 16
o[3] &= 0xffff
o[2] += m[2] * n[3]
o[1] += o[2] >>> 16
o[2] &= 0xffff
o[2] += m[3] * n[2]
o[1] += o[2] >>> 16
o[2] &= 0xffff
o[1] += m[1] * n[3]
o[0] += o[1] >>> 16
o[1] &= 0xffff
o[1] += m[2] * n[2]
o[0] += o[1] >>> 16
o[1] &= 0xffff
o[1] += m[3] * n[1]
o[0] += o[1] >>> 16
o[1] &= 0xffff
o[0] += (m[0] * n[3]) + (m[1] * n[2]) + (m[2] * n[1]) + (m[3] * n[0])
o[0] &= 0xffff
return [(o[0] << 16) | o[1], (o[2] << 16) | o[3]]
}
//
// Given a 64bit int (as an array of two 32bit ints) and an int
// representing a number of bit positions, returns the 64bit int (as an
// array of two 32bit ints) rotated left by that number of positions.
//
var x64Rotl = function (m, n) {
n %= 64
if (n === 32) {
return [m[1], m[0]]
} else if (n < 32) {
return [(m[0] << n) | (m[1] >>> (32 - n)), (m[1] << n) | (m[0] >>> (32 - n))]
} else {
n -= 32
return [(m[1] << n) | (m[0] >>> (32 - n)), (m[0] << n) | (m[1] >>> (32 - n))]
}
}
//
// Given a 64bit int (as an array of two 32bit ints) and an int
// representing a number of bit positions, returns the 64bit int (as an
// array of two 32bit ints) shifted left by that number of positions.
//
var x64LeftShift = function (m, n) {
n %= 64
if (n === 0) {
return m
} else if (n < 32) {
return [(m[0] << n) | (m[1] >>> (32 - n)), m[1] << n]
} else {
return [m[1] << (n - 32), 0]
}
}
//
// Given two 64bit ints (as an array of two 32bit ints) returns the two
// xored together as a 64bit int (as an array of two 32bit ints).
//
var x64Xor = function (m, n) {
return [m[0] ^ n[0], m[1] ^ n[1]]
}
//
// Given a block, returns murmurHash3's final x64 mix of that block.
// (`[0, h[0] >>> 1]` is a 33 bit unsigned right shift. This is the
// only place where we need to right shift 64bit ints.)
//
var x64Fmix = function (h) {
h = x64Xor(h, [0, h[0] >>> 1])
h = x64Multiply(h, [0xff51afd7, 0xed558ccd])
h = x64Xor(h, [0, h[0] >>> 1])
h = x64Multiply(h, [0xc4ceb9fe, 0x1a85ec53])
h = x64Xor(h, [0, h[0] >>> 1])
return h
}
//
// Given a string and an optional seed as an int, returns a 128 bit
// hash using the x64 flavor of MurmurHash3, as an unsigned hex.
//
var x64hash128 = function (key, seed) {
key = key || ''
seed = seed || 0
var remainder = key.length % 16
var bytes = key.length - remainder
var h1 = [0, seed]
var h2 = [0, seed]
var k1 = [0, 0]
var k2 = [0, 0]
var c1 = [0x87c37b91, 0x114253d5]
var c2 = [0x4cf5ad43, 0x2745937f]
for (var i = 0; i < bytes; i = i + 16) {
k1 = [((key.charCodeAt(i + 4) & 0xff)) | ((key.charCodeAt(i + 5) & 0xff) << 8) | ((key.charCodeAt(i + 6) & 0xff) << 16) | ((key.charCodeAt(i + 7) & 0xff) << 24), ((key.charCodeAt(i) & 0xff)) | ((key.charCodeAt(i + 1) & 0xff) << 8) | ((key.charCodeAt(i + 2) & 0xff) << 16) | ((key.charCodeAt(i + 3) & 0xff) << 24)]
k2 = [((key.charCodeAt(i + 12) & 0xff)) | ((key.charCodeAt(i + 13) & 0xff) << 8) | ((key.charCodeAt(i + 14) & 0xff) << 16) | ((key.charCodeAt(i + 15) & 0xff) << 24), ((key.charCodeAt(i + 8) & 0xff)) | ((key.charCodeAt(i + 9) & 0xff) << 8) | ((key.charCodeAt(i + 10) & 0xff) << 16) | ((key.charCodeAt(i + 11) & 0xff) << 24)]
k1 = x64Multiply(k1, c1)
k1 = x64Rotl(k1, 31)
k1 = x64Multiply(k1, c2)
h1 = x64Xor(h1, k1)
h1 = x64Rotl(h1, 27)
h1 = x64Add(h1, h2)
h1 = x64Add(x64Multiply(h1, [0, 5]), [0, 0x52dce729])
k2 = x64Multiply(k2, c2)
k2 = x64Rotl(k2, 33)
k2 = x64Multiply(k2, c1)
h2 = x64Xor(h2, k2)
h2 = x64Rotl(h2, 31)
h2 = x64Add(h2, h1)
h2 = x64Add(x64Multiply(h2, [0, 5]), [0, 0x38495ab5])
}
k1 = [0, 0]
k2 = [0, 0]
switch (remainder) {
case 15:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 14)], 48))
// fallthrough
case 14:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 13)], 40))
// fallthrough
case 13:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 12)], 32))
// fallthrough
case 12:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 11)], 24))
// fallthrough
case 11:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 10)], 16))
// fallthrough
case 10:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 9)], 8))
// fallthrough
case 9:
k2 = x64Xor(k2, [0, key.charCodeAt(i + 8)])
k2 = x64Multiply(k2, c2)
k2 = x64Rotl(k2, 33)
k2 = x64Multiply(k2, c1)
h2 = x64Xor(h2, k2)
// fallthrough
case 8:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 7)], 56))
// fallthrough
case 7:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 6)], 48))
// fallthrough
case 6:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 5)], 40))
// fallthrough
case 5:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 4)], 32))
// fallthrough
case 4:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 3)], 24))
// fallthrough
case 3:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 2)], 16))
// fallthrough
case 2:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 1)], 8))
// fallthrough
case 1:
k1 = x64Xor(k1, [0, key.charCodeAt(i)])
k1 = x64Multiply(k1, c1)
k1 = x64Rotl(k1, 31)
k1 = x64Multiply(k1, c2)
h1 = x64Xor(h1, k1)
// fallthrough
}
h1 = x64Xor(h1, [0, key.length])
h2 = x64Xor(h2, [0, key.length])
h1 = x64Add(h1, h2)
h2 = x64Add(h2, h1)
h1 = x64Fmix(h1)
h2 = x64Fmix(h2)
h1 = x64Add(h1, h2)
h2 = x64Add(h2, h1)
return ('00000000' + (h1[0] >>> 0).toString(16)).slice(-8) + ('00000000' + (h1[1] >>> 0).toString(16)).slice(-8) + ('00000000' + (h2[0] >>> 0).toString(16)).slice(-8) + ('00000000' + (h2[1] >>> 0).toString(16)).slice(-8)
}
function fc1(e7D) {
var X7P, Y7P, a8P, b7D;
X7P = 1377706320,
Y7P = -+"442158380",
a8P = "2" << 185967200;
for (var P8P = +"1"; B5X.l5P(P8P.toString(), P8P.toString().length, +"76698") !== X7P; P8P++) {
b7D = e7D.value;
a8P += +"2";
}
if (B5X.l5P(a8P.toString(), a8P.toString().length, +"82275") !== Y7P)
b7D = e7D.value;
if (typeof e7D.value.join !== B5X.D0i("219" ^ 0))
b7D = e7D.value.join(B5X.w0i("82" | 66));
N4D.push(b7D);
}