MCPcopy
hub / github.com/fingerprintjs/fingerprintjs / x64hash128

Function x64hash128

src/utils/hashing.ts:162–301  ·  view source on GitHub ↗
(input: string, seed?: number)

Source from the content-addressed store, hash-verified

160 * Benchmark https://jsbench.me/p4lkpaoabi/1
161 */
162export function x64hash128(input: string, seed?: number): string {
163 const key = getUTF8Bytes(input)
164 seed = seed || 0
165 const length = [0, key.length]
166 const remainder = length[1] % 16
167 const bytes = length[1] - remainder
168 const h1 = [0, seed]
169 const h2 = [0, seed]
170 const k1 = [0, 0]
171 const k2 = [0, 0]
172
173 let i: number
174 for (i = 0; i < bytes; i = i + 16) {
175 k1[0] = key[i + 4] | (key[i + 5] << 8) | (key[i + 6] << 16) | (key[i + 7] << 24)
176 k1[1] = key[i] | (key[i + 1] << 8) | (key[i + 2] << 16) | (key[i + 3] << 24)
177 k2[0] = key[i + 12] | (key[i + 13] << 8) | (key[i + 14] << 16) | (key[i + 15] << 24)
178 k2[1] = key[i + 8] | (key[i + 9] << 8) | (key[i + 10] << 16) | (key[i + 11] << 24)
179
180 x64Multiply(k1, C1)
181 x64Rotl(k1, 31)
182 x64Multiply(k1, C2)
183 x64Xor(h1, k1)
184 x64Rotl(h1, 27)
185 x64Add(h1, h2)
186 x64Multiply(h1, M)
187 x64Add(h1, N1)
188 x64Multiply(k2, C2)
189 x64Rotl(k2, 33)
190 x64Multiply(k2, C1)
191 x64Xor(h2, k2)
192 x64Rotl(h2, 31)
193 x64Add(h2, h1)
194 x64Multiply(h2, M)
195 x64Add(h2, N2)
196 }
197 k1[0] = 0
198 k1[1] = 0
199 k2[0] = 0
200 k2[1] = 0
201 const val = [0, 0]
202 switch (remainder) {
203 case 15:
204 val[1] = key[i + 14]
205 x64LeftShift(val, 48)
206 x64Xor(k2, val)
207 // fallthrough
208 case 14:
209 val[1] = key[i + 13]
210 x64LeftShift(val, 40)
211 x64Xor(k2, val)
212 // fallthrough
213 case 13:
214 val[1] = key[i + 12]
215 x64LeftShift(val, 32)
216 x64Xor(k2, val)
217 // fallthrough
218 case 12:
219 val[1] = key[i + 11]

Callers 2

hashComponentsFunction · 0.90
hashing.test.tsFile · 0.90

Calls 7

getUTF8BytesFunction · 0.90
x64MultiplyFunction · 0.85
x64RotlFunction · 0.85
x64XorFunction · 0.85
x64AddFunction · 0.85
x64LeftShiftFunction · 0.85
x64FmixFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…