rapidhash-js 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +100 -53
- package/lib/common-FK5Aq1u9.d.mts +7 -0
- package/lib/common-FK5Aq1u9.d.ts +7 -0
- package/lib/index.d.mts +6 -66
- package/lib/index.d.ts +6 -66
- package/lib/index.js +81 -300
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +80 -290
- package/lib/index.mjs.map +1 -1
- package/lib/v1.0/index.d.mts +31 -0
- package/lib/v1.0/index.d.ts +31 -0
- package/lib/v1.0/index.js +209 -0
- package/lib/v1.0/index.js.map +1 -0
- package/lib/v1.0/index.mjs +180 -0
- package/lib/v1.0/index.mjs.map +1 -0
- package/lib/v2.0/index.d.mts +31 -0
- package/lib/v2.0/index.d.ts +31 -0
- package/lib/v2.0/index.js +250 -0
- package/lib/v2.0/index.js.map +1 -0
- package/lib/v2.0/index.mjs +221 -0
- package/lib/v2.0/index.mjs.map +1 -0
- package/lib/v2.2/index.d.mts +31 -0
- package/lib/v2.2/index.d.ts +31 -0
- package/lib/v2.2/index.js +249 -0
- package/lib/v2.2/index.js.map +1 -0
- package/lib/v2.2/index.mjs +220 -0
- package/lib/v2.2/index.mjs.map +1 -0
- package/lib/v3.0/index.d.mts +62 -0
- package/lib/v3.0/index.d.ts +62 -0
- package/lib/v3.0/index.js +440 -0
- package/lib/v3.0/index.js.map +1 -0
- package/lib/v3.0/index.mjs +405 -0
- package/lib/v3.0/index.mjs.map +1 -0
- package/package.json +21 -12
package/lib/index.js
CHANGED
|
@@ -20,18 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
rapidhash: () =>
|
|
24
|
-
rapidhash_fast: () =>
|
|
25
|
-
rapidhash_protected: () =>
|
|
26
|
-
rapidhash_v1: () => rapidhash_v1,
|
|
27
|
-
rapidhash_v1_fast: () => rapidhash_v1_fast,
|
|
28
|
-
rapidhash_v1_protected: () => rapidhash_v1_protected,
|
|
29
|
-
rapidhash_v2_0: () => rapidhash_v2_0,
|
|
30
|
-
rapidhash_v2_0_fast: () => rapidhash_v2_0_fast,
|
|
31
|
-
rapidhash_v2_0_protected: () => rapidhash_v2_0_protected,
|
|
32
|
-
rapidhash_v2_2: () => rapidhash_v2_2,
|
|
33
|
-
rapidhash_v2_2_fast: () => rapidhash_v2_2_fast,
|
|
34
|
-
rapidhash_v2_2_protected: () => rapidhash_v2_2_protected
|
|
23
|
+
rapidhash: () => rapidhash,
|
|
24
|
+
rapidhash_fast: () => rapidhash_fast,
|
|
25
|
+
rapidhash_protected: () => rapidhash_protected
|
|
35
26
|
});
|
|
36
27
|
module.exports = __toCommonJS(index_exports);
|
|
37
28
|
|
|
@@ -40,29 +31,12 @@ function rapid_mix_fast(a, b) {
|
|
|
40
31
|
const m = a * b;
|
|
41
32
|
return BigInt.asUintN(64, m) ^ m >> 64n;
|
|
42
33
|
}
|
|
43
|
-
function rapidhash_epilogue_fast(a, b, secretA, secretB, len) {
|
|
44
|
-
const m0 = a * b;
|
|
45
|
-
const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * (m0 >> 64n ^ secretB);
|
|
46
|
-
return BigInt.asUintN(64, m1) ^ m1 >> 64n;
|
|
47
|
-
}
|
|
48
34
|
function rapid_mix_protected(a, b) {
|
|
49
35
|
const m = a * b;
|
|
50
36
|
return BigInt.asUintN(64, m) ^ m >> 64n ^ a ^ b;
|
|
51
37
|
}
|
|
52
|
-
function rapidhash_epilogue_protected(a0, b0, secretA, secretB, len) {
|
|
53
|
-
const m0 = a0 * b0;
|
|
54
|
-
const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;
|
|
55
|
-
const b1 = m0 >> 64n ^ secretB ^ b0;
|
|
56
|
-
const m1 = a1 * b1;
|
|
57
|
-
return BigInt.asUintN(64, m1) ^ m1 >> 64n ^ a1 ^ b1;
|
|
58
|
-
}
|
|
59
38
|
var read32x2Buffer = new Uint8Array(8);
|
|
60
39
|
var read32x2View = new DataView(read32x2Buffer.buffer);
|
|
61
|
-
function rapid_read32x2(buf, offset1, offset2) {
|
|
62
|
-
read32x2View.setUint32(4, buf.getUint32(offset1, true), true);
|
|
63
|
-
read32x2View.setUint32(0, buf.getUint32(offset2, true), true);
|
|
64
|
-
return read32x2View.getBigUint64(0, true);
|
|
65
|
-
}
|
|
66
40
|
var read32Buffer = new Uint8Array(8);
|
|
67
41
|
var read32View = new DataView(read32Buffer.buffer);
|
|
68
42
|
function rapid_read32(buf, offset) {
|
|
@@ -74,19 +48,8 @@ function rapid_read64(buf, offset) {
|
|
|
74
48
|
}
|
|
75
49
|
var readSmallBuffer = new Uint8Array(8);
|
|
76
50
|
var readSmallView = new DataView(readSmallBuffer.buffer);
|
|
77
|
-
function rapid_readSmall(buf, offset, k) {
|
|
78
|
-
readSmallBuffer[7] = buf.getUint8(offset);
|
|
79
|
-
readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));
|
|
80
|
-
readSmallBuffer[0] = buf.getUint8(offset + k - 1);
|
|
81
|
-
return readSmallView.getBigUint64(0, true);
|
|
82
|
-
}
|
|
83
51
|
var readBytesBuffer = new Uint8Array(8);
|
|
84
52
|
var readBytesView = new DataView(readBytesBuffer.buffer);
|
|
85
|
-
function rapid_readBytes(buf, offset1, offset2) {
|
|
86
|
-
readBytesBuffer[0] = buf.getUint8(offset2);
|
|
87
|
-
readBytesBuffer[7] = buf.getUint8(offset1);
|
|
88
|
-
return readBytesView.getBigUint64(0, true);
|
|
89
|
-
}
|
|
90
53
|
var textEncoder = new TextEncoder();
|
|
91
54
|
var utf8BufferSize = 2048;
|
|
92
55
|
var stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
|
|
@@ -106,16 +69,6 @@ function toDataView(message) {
|
|
|
106
69
|
return message;
|
|
107
70
|
}
|
|
108
71
|
var defaultRapidMumBehaviour = "fast";
|
|
109
|
-
var rapidMumImplementations = {
|
|
110
|
-
fast: {
|
|
111
|
-
rapid_mix: rapid_mix_fast,
|
|
112
|
-
rapidhash_epilogue: rapidhash_epilogue_fast
|
|
113
|
-
},
|
|
114
|
-
protected: {
|
|
115
|
-
rapid_mix: rapid_mix_protected,
|
|
116
|
-
rapidhash_epilogue: rapidhash_epilogue_protected
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
72
|
function isBigUint64(value) {
|
|
120
73
|
return value >= 0n && value <= 0xffffffffffffffffn;
|
|
121
74
|
}
|
|
@@ -139,89 +92,9 @@ function validateOptions(options, defaultSeed) {
|
|
|
139
92
|
return result;
|
|
140
93
|
}
|
|
141
94
|
|
|
142
|
-
// src/rapidhash_v1.0.ts
|
|
143
|
-
var RAPID_SEED = 0xbdd89aa982704029n;
|
|
144
|
-
var rapid_secret = [0x2d358dccaa6c78a5n, 0x8bb84b93962eacc9n, 0x4b33a62ed433d4a3n];
|
|
145
|
-
function rapidhash_v1_internal(key, seed, secret, rapid_mix, rapidhash_epilogue) {
|
|
146
|
-
const len = key.byteLength;
|
|
147
|
-
const lenBI = BigInt(key.byteLength);
|
|
148
|
-
seed ^= rapid_mix(seed ^ secret[0], secret[1]) ^ lenBI;
|
|
149
|
-
let a;
|
|
150
|
-
let b;
|
|
151
|
-
if (len <= 16) {
|
|
152
|
-
if (len >= 4) {
|
|
153
|
-
const last = len - 4;
|
|
154
|
-
a = rapid_read32x2(key, 0, last);
|
|
155
|
-
const delta = (len & 24) >> (len >> 3);
|
|
156
|
-
b = rapid_read32x2(key, delta, last - delta);
|
|
157
|
-
} else if (len > 0) {
|
|
158
|
-
a = rapid_readSmall(key, 0, len);
|
|
159
|
-
b = 0n;
|
|
160
|
-
} else {
|
|
161
|
-
a = 0n;
|
|
162
|
-
b = 0n;
|
|
163
|
-
}
|
|
164
|
-
} else {
|
|
165
|
-
let i = len;
|
|
166
|
-
let p = 0;
|
|
167
|
-
if (i > 48) {
|
|
168
|
-
let see1 = seed;
|
|
169
|
-
let see2 = seed;
|
|
170
|
-
while (i >= 96) {
|
|
171
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
172
|
-
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
173
|
-
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
174
|
-
seed = rapid_mix(rapid_read64(key, p + 48) ^ secret[0], rapid_read64(key, p + 56) ^ seed);
|
|
175
|
-
see1 = rapid_mix(rapid_read64(key, p + 64) ^ secret[1], rapid_read64(key, p + 72) ^ see1);
|
|
176
|
-
see2 = rapid_mix(rapid_read64(key, p + 80) ^ secret[2], rapid_read64(key, p + 88) ^ see2);
|
|
177
|
-
p += 96;
|
|
178
|
-
i -= 96;
|
|
179
|
-
}
|
|
180
|
-
if (i >= 48) {
|
|
181
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
182
|
-
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
183
|
-
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
184
|
-
p += 48;
|
|
185
|
-
i -= 48;
|
|
186
|
-
}
|
|
187
|
-
seed ^= see1 ^ see2;
|
|
188
|
-
}
|
|
189
|
-
if (i > 16) {
|
|
190
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed ^ secret[1]);
|
|
191
|
-
if (i > 32) {
|
|
192
|
-
seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
a = rapid_read64(key, p + i - 16);
|
|
196
|
-
b = rapid_read64(key, p + i - 8);
|
|
197
|
-
}
|
|
198
|
-
a ^= secret[1];
|
|
199
|
-
b ^= seed;
|
|
200
|
-
return rapidhash_epilogue(a, b, secret[0], secret[1], lenBI);
|
|
201
|
-
}
|
|
202
|
-
function rapidhash_v1(message, options) {
|
|
203
|
-
const { seed, rapidMumBehaviour } = validateOptions(options, RAPID_SEED);
|
|
204
|
-
const { rapid_mix, rapidhash_epilogue } = rapidMumImplementations[rapidMumBehaviour];
|
|
205
|
-
return rapidhash_v1_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);
|
|
206
|
-
}
|
|
207
|
-
function rapidhash_v1_fast(message, options) {
|
|
208
|
-
const { seed } = validateOptions(options, RAPID_SEED);
|
|
209
|
-
return rapidhash_v1_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogue_fast);
|
|
210
|
-
}
|
|
211
|
-
function rapidhash_v1_protected(message, options) {
|
|
212
|
-
const { seed } = validateOptions(options, RAPID_SEED);
|
|
213
|
-
return rapidhash_v1_internal(
|
|
214
|
-
toDataView(message),
|
|
215
|
-
seed,
|
|
216
|
-
rapid_secret,
|
|
217
|
-
rapid_mix_protected,
|
|
218
|
-
rapidhash_epilogue_protected
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
95
|
// src/common_v2.ts
|
|
223
|
-
var
|
|
224
|
-
var
|
|
96
|
+
var RAPID_SEED = 0n;
|
|
97
|
+
var rapid_secret = [
|
|
225
98
|
0x2d358dccaa6c78a5n,
|
|
226
99
|
0x8bb84b93962eacc9n,
|
|
227
100
|
0x4b33a62ed433d4a3n,
|
|
@@ -232,124 +105,52 @@ var rapid_secret2 = [
|
|
|
232
105
|
0xaaaaaaaaaaaaaaaan
|
|
233
106
|
];
|
|
234
107
|
|
|
235
|
-
// src/
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const last = len - 4;
|
|
250
|
-
a = rapid_read32(key, 0);
|
|
251
|
-
b = rapid_read32(key, last);
|
|
252
|
-
}
|
|
253
|
-
} else if (len > 0) {
|
|
254
|
-
a = rapid_readSmall(key, 0, len);
|
|
255
|
-
b = 0n;
|
|
256
|
-
} else {
|
|
257
|
-
a = 0n;
|
|
258
|
-
b = 0n;
|
|
259
|
-
}
|
|
260
|
-
} else if (len > 56) {
|
|
261
|
-
let i = len;
|
|
262
|
-
let p = 0;
|
|
263
|
-
let see1 = seed;
|
|
264
|
-
let see2 = seed;
|
|
265
|
-
let see3456;
|
|
266
|
-
if (i >= 112) {
|
|
267
|
-
let see3 = seed;
|
|
268
|
-
let see4 = seed;
|
|
269
|
-
let see5 = seed;
|
|
270
|
-
let see6 = seed;
|
|
271
|
-
do {
|
|
272
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
273
|
-
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
274
|
-
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
275
|
-
see3 = rapid_mix(rapid_read64(key, p + 48) ^ secret[3], rapid_read64(key, p + 56) ^ see3);
|
|
276
|
-
see4 = rapid_mix(rapid_read64(key, p + 64) ^ secret[4], rapid_read64(key, p + 72) ^ see4);
|
|
277
|
-
see5 = rapid_mix(rapid_read64(key, p + 80) ^ secret[5], rapid_read64(key, p + 88) ^ see5);
|
|
278
|
-
see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);
|
|
279
|
-
p += 112;
|
|
280
|
-
i -= 112;
|
|
281
|
-
} while (i >= 112);
|
|
282
|
-
see3456 = see3 ^ see4 ^ see5 ^ see6;
|
|
283
|
-
} else {
|
|
284
|
-
see3456 = 0n;
|
|
285
|
-
}
|
|
286
|
-
if (i >= 48) {
|
|
287
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
288
|
-
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
289
|
-
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
290
|
-
p += 48;
|
|
291
|
-
i -= 48;
|
|
292
|
-
if (i >= 48) {
|
|
293
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
294
|
-
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
295
|
-
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
296
|
-
p += 48;
|
|
297
|
-
i -= 48;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
seed ^= see1 ^ see2 ^ see3456;
|
|
301
|
-
if (i > 16) {
|
|
302
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);
|
|
303
|
-
if (i > 32) {
|
|
304
|
-
seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
a = rapid_read64(key, p + i - 16);
|
|
308
|
-
b = rapid_read64(key, p + i - 8);
|
|
309
|
-
} else {
|
|
310
|
-
seed = rapid_mix(rapid_read64(key, 0) ^ secret[0], rapid_read64(key, 8) ^ seed);
|
|
311
|
-
if (len > 32) {
|
|
312
|
-
seed = rapid_mix(rapid_read64(key, 16) ^ secret[1], rapid_read64(key, 24) ^ seed);
|
|
313
|
-
if (len > 48) {
|
|
314
|
-
seed = rapid_mix(rapid_read64(key, 32) ^ secret[0], rapid_read64(key, 40) ^ seed);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
a = rapid_read64(key, len - 16);
|
|
318
|
-
b = rapid_read64(key, len - 8);
|
|
319
|
-
}
|
|
320
|
-
a ^= secret[1];
|
|
321
|
-
b ^= seed;
|
|
322
|
-
return rapidhash_epilogue(a, b, secret[7], secret[1], lenBI);
|
|
323
|
-
}
|
|
324
|
-
function rapidhash_v2_0(message, options) {
|
|
325
|
-
const { seed, rapidMumBehaviour } = validateOptions(options, RAPID_SEED2);
|
|
326
|
-
const { rapid_mix, rapidhash_epilogue } = rapidMumImplementations[rapidMumBehaviour];
|
|
327
|
-
return rapidhash_v2_0_internal(toDataView(message), seed, rapid_secret2, rapid_mix, rapidhash_epilogue);
|
|
328
|
-
}
|
|
329
|
-
function rapidhash_v2_0_fast(message, options) {
|
|
330
|
-
const { seed } = validateOptions(options, RAPID_SEED2);
|
|
331
|
-
return rapidhash_v2_0_internal(toDataView(message), seed, rapid_secret2, rapid_mix_fast, rapidhash_epilogue_fast);
|
|
108
|
+
// src/v3.0/common_v3.ts
|
|
109
|
+
var readSmallV3Buffer = new Uint8Array(8);
|
|
110
|
+
var readSmallV3View = new DataView(readSmallV3Buffer.buffer);
|
|
111
|
+
function rapid_readSmallV3(input, len) {
|
|
112
|
+
const v = input.getUint8(0);
|
|
113
|
+
readSmallV3Buffer[6] = v >> 3;
|
|
114
|
+
readSmallV3Buffer[5] = v << 5;
|
|
115
|
+
readSmallV3Buffer[0] = input.getUint8(len - 1);
|
|
116
|
+
return readSmallV3View.getBigUint64(0, true);
|
|
117
|
+
}
|
|
118
|
+
function rapidhash_epilogueV3_fast(a, b, secret, i) {
|
|
119
|
+
const m0 = a * b;
|
|
120
|
+
const m1 = (BigInt.asUintN(64, m0) ^ secret[7]) * (m0 >> 64n ^ secret[1] ^ i);
|
|
121
|
+
return BigInt.asUintN(64, m1) ^ m1 >> 64n;
|
|
332
122
|
}
|
|
333
|
-
function
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
rapid_mix_protected,
|
|
340
|
-
rapidhash_epilogue_protected
|
|
341
|
-
);
|
|
123
|
+
function rapidhash_epilogueV3_protected(a0, b0, secret, i) {
|
|
124
|
+
const m0 = a0 * b0;
|
|
125
|
+
const a1 = BigInt.asUintN(64, m0) ^ secret[7] ^ a0;
|
|
126
|
+
const b1 = m0 >> 64n ^ secret[1] ^ i ^ b0;
|
|
127
|
+
const m1 = a1 * b1;
|
|
128
|
+
return BigInt.asUintN(64, m1) ^ m1 >> 64n ^ a1 ^ b1;
|
|
342
129
|
}
|
|
130
|
+
var rapidMumImplementationsV3 = {
|
|
131
|
+
fast: {
|
|
132
|
+
rapid_mix: rapid_mix_fast,
|
|
133
|
+
rapidhash_epilogue: rapidhash_epilogueV3_fast
|
|
134
|
+
},
|
|
135
|
+
protected: {
|
|
136
|
+
rapid_mix: rapid_mix_protected,
|
|
137
|
+
rapidhash_epilogue: rapidhash_epilogueV3_protected
|
|
138
|
+
}
|
|
139
|
+
};
|
|
343
140
|
|
|
344
|
-
// src/
|
|
345
|
-
function
|
|
141
|
+
// src/v3.0/rapidhash_v3.0.ts
|
|
142
|
+
function rapidhash_v3_0_internal(key, seed, secret, rapid_mix, rapidhash_epilogue) {
|
|
346
143
|
const len = key.byteLength;
|
|
347
144
|
const lenBI = BigInt(key.byteLength);
|
|
348
|
-
seed ^= rapid_mix(seed ^ secret[2], secret[1])
|
|
145
|
+
seed ^= rapid_mix(seed ^ secret[2], secret[1]);
|
|
349
146
|
let a;
|
|
350
147
|
let b;
|
|
148
|
+
let i = len;
|
|
149
|
+
let bi;
|
|
351
150
|
if (len <= 16) {
|
|
151
|
+
bi = lenBI;
|
|
352
152
|
if (len >= 4) {
|
|
153
|
+
seed ^= lenBI;
|
|
353
154
|
if (len >= 8) {
|
|
354
155
|
const last = len - 8;
|
|
355
156
|
a = rapid_read64(key, 0);
|
|
@@ -360,29 +161,17 @@ function rapidhash_v2_2_internal(key, seed, secret, rapid_mix, rapidhash_epilogu
|
|
|
360
161
|
b = rapid_read32(key, last);
|
|
361
162
|
}
|
|
362
163
|
} else if (len > 0) {
|
|
363
|
-
a =
|
|
164
|
+
a = rapid_readSmallV3(key, len);
|
|
364
165
|
b = BigInt(key.getUint8(len >> 1));
|
|
365
166
|
} else {
|
|
366
167
|
a = 0n;
|
|
367
168
|
b = 0n;
|
|
368
169
|
}
|
|
369
|
-
} else if (len <= 64) {
|
|
370
|
-
seed = rapid_mix(rapid_read64(key, 0) ^ secret[0], rapid_read64(key, 8) ^ seed);
|
|
371
|
-
if (len > 32) {
|
|
372
|
-
seed = rapid_mix(rapid_read64(key, 16) ^ secret[1], rapid_read64(key, 24) ^ seed);
|
|
373
|
-
if (len > 48) {
|
|
374
|
-
seed = rapid_mix(rapid_read64(key, 32) ^ secret[1], rapid_read64(key, 40) ^ seed);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
a = rapid_read64(key, len - 16);
|
|
378
|
-
b = rapid_read64(key, len - 8);
|
|
379
170
|
} else {
|
|
380
|
-
let i = len;
|
|
381
171
|
let p = 0;
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (i >= 112) {
|
|
172
|
+
if (i > 112) {
|
|
173
|
+
let see1 = seed;
|
|
174
|
+
let see2 = seed;
|
|
386
175
|
let see3 = seed;
|
|
387
176
|
let see4 = seed;
|
|
388
177
|
let see5 = seed;
|
|
@@ -397,71 +186,63 @@ function rapidhash_v2_2_internal(key, seed, secret, rapid_mix, rapidhash_epilogu
|
|
|
397
186
|
see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);
|
|
398
187
|
p += 112;
|
|
399
188
|
i -= 112;
|
|
400
|
-
} while (i
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
189
|
+
} while (i > 112);
|
|
190
|
+
seed ^= see1;
|
|
191
|
+
see2 ^= see3;
|
|
192
|
+
see4 ^= see5;
|
|
193
|
+
seed ^= see6;
|
|
194
|
+
see2 ^= see4;
|
|
195
|
+
seed ^= see2;
|
|
404
196
|
}
|
|
405
|
-
|
|
406
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
407
|
-
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
408
|
-
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
409
|
-
p += 48;
|
|
410
|
-
i -= 48;
|
|
411
|
-
if (i >= 48) {
|
|
412
|
-
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
413
|
-
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
414
|
-
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
415
|
-
p += 48;
|
|
416
|
-
i -= 48;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
seed ^= see1 ^ see2 ^ see3456;
|
|
197
|
+
bi = BigInt(i);
|
|
420
198
|
if (i > 16) {
|
|
421
199
|
seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);
|
|
422
200
|
if (i > 32) {
|
|
423
201
|
seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);
|
|
202
|
+
if (i > 48) {
|
|
203
|
+
seed = rapid_mix(rapid_read64(key, p + 32) ^ secret[1], rapid_read64(key, p + 40) ^ seed);
|
|
204
|
+
if (i > 64) {
|
|
205
|
+
seed = rapid_mix(rapid_read64(key, p + 48) ^ secret[1], rapid_read64(key, p + 56) ^ seed);
|
|
206
|
+
if (i > 80) {
|
|
207
|
+
seed = rapid_mix(rapid_read64(key, p + 64) ^ secret[2], rapid_read64(key, p + 72) ^ seed);
|
|
208
|
+
if (i > 96) {
|
|
209
|
+
seed = rapid_mix(rapid_read64(key, p + 80) ^ secret[1], rapid_read64(key, p + 88) ^ seed);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
424
214
|
}
|
|
425
215
|
}
|
|
426
|
-
a = rapid_read64(key, p + i - 16);
|
|
216
|
+
a = rapid_read64(key, p + i - 16) ^ bi;
|
|
427
217
|
b = rapid_read64(key, p + i - 8);
|
|
428
218
|
}
|
|
429
219
|
a ^= secret[1];
|
|
430
220
|
b ^= seed;
|
|
431
|
-
return rapidhash_epilogue(a, b, secret
|
|
221
|
+
return rapidhash_epilogue(a, b, secret, bi);
|
|
432
222
|
}
|
|
433
|
-
function
|
|
434
|
-
const { seed, rapidMumBehaviour } = validateOptions(options,
|
|
435
|
-
const { rapid_mix, rapidhash_epilogue } =
|
|
436
|
-
return
|
|
223
|
+
function rapidhash(message, options) {
|
|
224
|
+
const { seed, rapidMumBehaviour } = validateOptions(options, RAPID_SEED);
|
|
225
|
+
const { rapid_mix, rapidhash_epilogue } = rapidMumImplementationsV3[rapidMumBehaviour];
|
|
226
|
+
return rapidhash_v3_0_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);
|
|
437
227
|
}
|
|
438
|
-
function
|
|
439
|
-
const { seed } = validateOptions(options,
|
|
440
|
-
return
|
|
228
|
+
function rapidhash_fast(message, options) {
|
|
229
|
+
const { seed } = validateOptions(options, RAPID_SEED);
|
|
230
|
+
return rapidhash_v3_0_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogueV3_fast);
|
|
441
231
|
}
|
|
442
|
-
function
|
|
443
|
-
const { seed } = validateOptions(options,
|
|
444
|
-
return
|
|
232
|
+
function rapidhash_protected(message, options) {
|
|
233
|
+
const { seed } = validateOptions(options, RAPID_SEED);
|
|
234
|
+
return rapidhash_v3_0_internal(
|
|
445
235
|
toDataView(message),
|
|
446
236
|
seed,
|
|
447
|
-
|
|
237
|
+
rapid_secret,
|
|
448
238
|
rapid_mix_protected,
|
|
449
|
-
|
|
239
|
+
rapidhash_epilogueV3_protected
|
|
450
240
|
);
|
|
451
241
|
}
|
|
452
242
|
// Annotate the CommonJS export names for ESM import in node:
|
|
453
243
|
0 && (module.exports = {
|
|
454
244
|
rapidhash,
|
|
455
245
|
rapidhash_fast,
|
|
456
|
-
rapidhash_protected
|
|
457
|
-
rapidhash_v1,
|
|
458
|
-
rapidhash_v1_fast,
|
|
459
|
-
rapidhash_v1_protected,
|
|
460
|
-
rapidhash_v2_0,
|
|
461
|
-
rapidhash_v2_0_fast,
|
|
462
|
-
rapidhash_v2_0_protected,
|
|
463
|
-
rapidhash_v2_2,
|
|
464
|
-
rapidhash_v2_2_fast,
|
|
465
|
-
rapidhash_v2_2_protected
|
|
246
|
+
rapidhash_protected
|
|
466
247
|
});
|
|
467
248
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/common.ts","../src/rapidhash_v1.0.ts","../src/common_v2.ts","../src/rapidhash_v2.0.ts","../src/rapidhash_v2.2.ts"],"sourcesContent":["import {rapidhash_v1, rapidhash_v1_fast, rapidhash_v1_protected} from './rapidhash_v1.0';\nimport {rapidhash_v2_0, rapidhash_v2_0_fast, rapidhash_v2_0_protected} from './rapidhash_v2.0';\nimport {rapidhash_v2_2, rapidhash_v2_2_fast, rapidhash_v2_2_protected} from './rapidhash_v2.2';\n\nexport {\n rapidhash_v1,\n rapidhash_v1_fast,\n rapidhash_v1_protected,\n rapidhash_v2_0,\n rapidhash_v2_0_fast,\n rapidhash_v2_0_protected,\n rapidhash_v2_2,\n rapidhash_v2_2_fast,\n rapidhash_v2_2_protected,\n // Default version is v2.2\n rapidhash_v2_2 as rapidhash,\n rapidhash_v2_2_fast as rapidhash_fast,\n rapidhash_v2_2_protected as rapidhash_protected,\n};\n","export type RapidMix = (a: bigint, b: bigint) => bigint;\nexport type RapidhashEpilogue = (a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint) => bigint;\n\nexport function rapid_mix_fast(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n);\n}\n\nexport function rapidhash_epilogue_fast(a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint): bigint {\n const m0 = a * b;\n const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * ((m0 >> 64n) ^ secretB);\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n);\n}\n\nexport function rapid_mix_protected(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n) ^ a ^ b;\n}\n\nexport function rapidhash_epilogue_protected(\n a0: bigint,\n b0: bigint,\n secretA: bigint,\n secretB: bigint,\n len: bigint,\n): bigint {\n const m0 = a0 * b0;\n const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;\n const b1 = (m0 >> 64n) ^ secretB ^ b0;\n const m1 = a1 * b1;\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n) ^ a1 ^ b1;\n}\n\n// ---\n\nconst read32x2Buffer = new Uint8Array(8);\nconst read32x2View = new DataView(read32x2Buffer.buffer);\n\nexport function rapid_read32x2(buf: DataView, offset1: number, offset2: number): bigint {\n read32x2View.setUint32(4, buf.getUint32(offset1, true), true);\n read32x2View.setUint32(0, buf.getUint32(offset2, true), true);\n return read32x2View.getBigUint64(0, true);\n}\n\nconst read32Buffer = new Uint8Array(8);\nconst read32View = new DataView(read32Buffer.buffer);\n\nexport function rapid_read32(buf: DataView, offset: number): bigint {\n read32View.setUint32(0, buf.getUint32(offset, true), true);\n return read32View.getBigUint64(0, true);\n}\n\nexport function rapid_read64(buf: DataView, offset: number): bigint {\n return buf.getBigUint64(offset, true);\n}\n\nconst readSmallBuffer = new Uint8Array(8);\nconst readSmallView = new DataView(readSmallBuffer.buffer);\n\nexport function rapid_readSmall(buf: DataView, offset: number, k: number): bigint {\n readSmallBuffer[7] = buf.getUint8(offset);\n readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));\n readSmallBuffer[0] = buf.getUint8(offset + k - 1);\n return readSmallView.getBigUint64(0, true);\n}\n\nconst readBytesBuffer = new Uint8Array(8);\nconst readBytesView = new DataView(readBytesBuffer.buffer);\n\nexport function rapid_readBytes(buf: DataView, offset1: number, offset2: number): bigint {\n readBytesBuffer[0] = buf.getUint8(offset2);\n readBytesBuffer[7] = buf.getUint8(offset1);\n return readBytesView.getBigUint64(0, true);\n}\n\n// ---\n\nconst textEncoder = new TextEncoder();\nconst utf8BufferSize = 2048;\nconst stringLengthThresholdToUseBuffer = utf8BufferSize / 3;\nconst utf8Buffer = new Uint8Array(utf8BufferSize);\n\nexport function toDataView(message: string | Uint8Array | DataView): DataView {\n if (typeof message === 'string') {\n if (message.length <= stringLengthThresholdToUseBuffer) {\n const {written} = textEncoder.encodeInto(message, utf8Buffer);\n return new DataView(utf8Buffer.buffer, 0, written);\n }\n\n const utf8bytes = textEncoder.encode(message);\n return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);\n }\n\n if (message instanceof Uint8Array) {\n return new DataView(message.buffer, message.byteOffset, message.byteLength);\n }\n\n return message;\n}\n\n// ---\n\nexport type RapidMumBehaviour = 'fast' | 'protected';\nconst defaultRapidMumBehaviour: RapidMumBehaviour = 'fast';\n\nexport interface RapidhashOptions {\n seed: bigint;\n rapidMumBehaviour: RapidMumBehaviour;\n}\n\nexport const rapidMumImplementations: {\n [behaviour in RapidMumBehaviour]: {\n rapid_mix: RapidMix;\n rapidhash_epilogue: RapidhashEpilogue;\n };\n} = {\n fast: {\n rapid_mix: rapid_mix_fast,\n rapidhash_epilogue: rapidhash_epilogue_fast,\n },\n protected: {\n rapid_mix: rapid_mix_protected,\n rapidhash_epilogue: rapidhash_epilogue_protected,\n },\n};\n\nfunction isBigUint64(value: bigint): boolean {\n return value >= 0n && value <= 0xffff_ffff_ffff_ffffn;\n}\n\nexport function validateOptions(options: Partial<RapidhashOptions> | undefined, defaultSeed: bigint): RapidhashOptions {\n const result: RapidhashOptions = {\n seed: defaultSeed,\n rapidMumBehaviour: defaultRapidMumBehaviour,\n };\n\n if (options === undefined) {\n return result;\n }\n\n if (options.seed !== undefined) {\n if (!isBigUint64(options.seed)) {\n throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);\n }\n result.seed = options.seed;\n }\n\n if (options.rapidMumBehaviour !== undefined) {\n result.rapidMumBehaviour = options.rapidMumBehaviour;\n }\n\n return result;\n}\n","import {\n type RapidMix,\n type RapidhashEpilogue,\n type RapidhashOptions,\n rapidMumImplementations,\n rapid_mix_fast,\n rapid_mix_protected,\n rapid_read32x2,\n rapid_read64,\n rapid_readSmall,\n rapidhash_epilogue_fast,\n rapidhash_epilogue_protected,\n toDataView,\n validateOptions,\n} from './common';\n\ntype RapidSecret = [bigint, bigint, bigint];\n\nconst RAPID_SEED = 0xbdd89aa982704029n;\nconst rapid_secret: RapidSecret = [0x2d358dccaa6c78a5n, 0x8bb84b93962eacc9n, 0x4b33a62ed433d4a3n];\n\n// ---\n\nfunction rapidhash_v1_internal(\n key: DataView,\n seed: bigint,\n secret: RapidSecret,\n rapid_mix: RapidMix,\n rapidhash_epilogue: RapidhashEpilogue,\n): bigint {\n const len = key.byteLength;\n const lenBI = BigInt(key.byteLength);\n\n seed ^= rapid_mix(seed ^ secret[0], secret[1]) ^ lenBI;\n\n let a: bigint;\n let b: bigint;\n\n if (len <= 16) {\n if (len >= 4) {\n const last = len - 4;\n a = rapid_read32x2(key, 0, last);\n const delta = (len & 24) >> (len >> 3);\n b = rapid_read32x2(key, delta, last - delta);\n } else if (len > 0) {\n a = rapid_readSmall(key, 0, len);\n b = 0n;\n } else {\n a = 0n;\n b = 0n;\n }\n } else {\n let i = len;\n let p = 0;\n\n if (i > 48) {\n let see1 = seed;\n let see2 = seed;\n\n while (i >= 96) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n seed = rapid_mix(rapid_read64(key, p + 48) ^ secret[0], rapid_read64(key, p + 56) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 64) ^ secret[1], rapid_read64(key, p + 72) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 80) ^ secret[2], rapid_read64(key, p + 88) ^ see2);\n p += 96;\n i -= 96;\n }\n if (i >= 48) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n p += 48;\n i -= 48;\n }\n\n seed ^= see1 ^ see2;\n }\n\n if (i > 16) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed ^ secret[1]);\n if (i > 32) {\n seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);\n }\n }\n a = rapid_read64(key, p + i - 16);\n b = rapid_read64(key, p + i - 8);\n }\n a ^= secret[1];\n b ^= seed;\n\n return rapidhash_epilogue(a, b, secret[0], secret[1], lenBI);\n}\n\n// ---\n\n/**\n * Calculate a 64-bit hash value of the given message.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.\n */\nexport function rapidhash_v1(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint {\n const {seed, rapidMumBehaviour} = validateOptions(options, RAPID_SEED);\n const {rapid_mix, rapidhash_epilogue} = rapidMumImplementations[rapidMumBehaviour];\n\n return rapidhash_v1_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_v1_fast(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v1_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogue_fast);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_v1_protected(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v1_internal(\n toDataView(message),\n seed,\n rapid_secret,\n rapid_mix_protected,\n rapidhash_epilogue_protected,\n );\n}\n","export type RapidSecret = [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint];\n\nexport const RAPID_SEED = 0n;\nexport const rapid_secret: RapidSecret = [\n 0x2d358dccaa6c78a5n,\n 0x8bb84b93962eacc9n,\n 0x4b33a62ed433d4a3n,\n 0x4d5a2da51de1aa47n,\n 0xa0761d6478bd642fn,\n 0xe7037ed1a0b428dbn,\n 0x90ed1765281c388cn,\n 0xaaaaaaaaaaaaaaaan,\n];\n","import {\n type RapidMix,\n type RapidhashEpilogue,\n type RapidhashOptions,\n rapidMumImplementations,\n rapid_mix_fast,\n rapid_mix_protected,\n rapid_read32,\n rapid_read64,\n rapid_readSmall,\n rapidhash_epilogue_fast,\n rapidhash_epilogue_protected,\n toDataView,\n validateOptions,\n} from './common';\nimport {RAPID_SEED, type RapidSecret, rapid_secret} from './common_v2';\n\n// ---\n\nfunction rapidhash_v2_0_internal(\n key: DataView,\n seed: bigint,\n secret: RapidSecret,\n rapid_mix: RapidMix,\n rapidhash_epilogue: RapidhashEpilogue,\n): bigint {\n const len = key.byteLength;\n const lenBI = BigInt(key.byteLength);\n\n seed ^= rapid_mix(seed ^ secret[2], secret[1]) ^ lenBI;\n\n let a: bigint;\n let b: bigint;\n\n if (len <= 16) {\n if (len >= 4) {\n if (len >= 8) {\n const last = len - 8;\n a = rapid_read64(key, 0);\n b = rapid_read64(key, last);\n } else {\n const last = len - 4;\n a = rapid_read32(key, 0);\n b = rapid_read32(key, last);\n }\n } else if (len > 0) {\n a = rapid_readSmall(key, 0, len);\n b = 0n;\n } else {\n a = 0n;\n b = 0n;\n }\n } else if (len > 56) {\n let i = len;\n let p = 0;\n let see1 = seed;\n let see2 = seed;\n let see3456: bigint;\n\n if (i >= 112) {\n let see3 = seed;\n let see4 = seed;\n let see5 = seed;\n let see6 = seed;\n do {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n see3 = rapid_mix(rapid_read64(key, p + 48) ^ secret[3], rapid_read64(key, p + 56) ^ see3);\n see4 = rapid_mix(rapid_read64(key, p + 64) ^ secret[4], rapid_read64(key, p + 72) ^ see4);\n see5 = rapid_mix(rapid_read64(key, p + 80) ^ secret[5], rapid_read64(key, p + 88) ^ see5);\n see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);\n p += 112;\n i -= 112;\n } while (i >= 112);\n\n see3456 = see3 ^ see4 ^ see5 ^ see6;\n } else {\n see3456 = 0n;\n }\n\n if (i >= 48) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n p += 48;\n i -= 48;\n if (i >= 48) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n p += 48;\n i -= 48;\n }\n }\n\n seed ^= see1 ^ see2 ^ see3456;\n\n if (i > 16) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);\n if (i > 32) {\n seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);\n }\n }\n\n a = rapid_read64(key, p + i - 16);\n b = rapid_read64(key, p + i - 8);\n } else {\n seed = rapid_mix(rapid_read64(key, 0) ^ secret[0], rapid_read64(key, 8) ^ seed);\n if (len > 32) {\n seed = rapid_mix(rapid_read64(key, 16) ^ secret[1], rapid_read64(key, 24) ^ seed);\n if (len > 48) {\n seed = rapid_mix(rapid_read64(key, 32) ^ secret[0], rapid_read64(key, 40) ^ seed);\n }\n }\n\n a = rapid_read64(key, len - 16);\n b = rapid_read64(key, len - 8);\n }\n a ^= secret[1];\n b ^= seed;\n\n return rapidhash_epilogue(a, b, secret[7], secret[1], lenBI);\n}\n\n// ---\n\n/**\n * Calculate a 64-bit hash value of the given message.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.\n */\nexport function rapidhash_v2_0(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint {\n const {seed, rapidMumBehaviour} = validateOptions(options, RAPID_SEED);\n const {rapid_mix, rapidhash_epilogue} = rapidMumImplementations[rapidMumBehaviour];\n\n return rapidhash_v2_0_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_v2_0_fast(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v2_0_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogue_fast);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_v2_0_protected(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v2_0_internal(\n toDataView(message),\n seed,\n rapid_secret,\n rapid_mix_protected,\n rapidhash_epilogue_protected,\n );\n}\n","import {\n type RapidMix,\n type RapidhashEpilogue,\n type RapidhashOptions,\n rapidMumImplementations,\n rapid_mix_fast,\n rapid_mix_protected,\n rapid_read32,\n rapid_read64,\n rapid_readBytes,\n rapidhash_epilogue_fast,\n rapidhash_epilogue_protected,\n toDataView,\n validateOptions,\n} from './common';\nimport {RAPID_SEED, type RapidSecret, rapid_secret} from './common_v2';\n\n// ---\n\nfunction rapidhash_v2_2_internal(\n key: DataView,\n seed: bigint,\n secret: RapidSecret,\n rapid_mix: RapidMix,\n rapidhash_epilogue: RapidhashEpilogue,\n): bigint {\n const len = key.byteLength;\n const lenBI = BigInt(key.byteLength);\n\n seed ^= rapid_mix(seed ^ secret[2], secret[1]) ^ lenBI;\n\n let a: bigint;\n let b: bigint;\n\n if (len <= 16) {\n if (len >= 4) {\n if (len >= 8) {\n const last = len - 8;\n a = rapid_read64(key, 0);\n b = rapid_read64(key, last);\n } else {\n const last = len - 4;\n a = rapid_read32(key, 0);\n b = rapid_read32(key, last);\n }\n } else if (len > 0) {\n //a = rapid_readSmall(key, 0, len);\n a = rapid_readBytes(key, 0, len - 1);\n b = BigInt(key.getUint8(len >> 1));\n } else {\n a = 0n;\n b = 0n;\n }\n } else if (len <= 64) {\n seed = rapid_mix(rapid_read64(key, 0) ^ secret[0], rapid_read64(key, 8) ^ seed);\n if (len > 32) {\n seed = rapid_mix(rapid_read64(key, 16) ^ secret[1], rapid_read64(key, 24) ^ seed);\n if (len > 48) {\n seed = rapid_mix(rapid_read64(key, 32) ^ secret[1], rapid_read64(key, 40) ^ seed);\n }\n }\n a = rapid_read64(key, len - 16);\n b = rapid_read64(key, len - 8);\n } else {\n let i = len;\n let p = 0;\n let see1 = seed;\n let see2 = seed;\n let see3456: bigint; // = 0n;\n\n if (i >= 112) {\n let see3 = seed;\n let see4 = seed;\n let see5 = seed;\n let see6 = seed;\n do {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n see3 = rapid_mix(rapid_read64(key, p + 48) ^ secret[3], rapid_read64(key, p + 56) ^ see3);\n see4 = rapid_mix(rapid_read64(key, p + 64) ^ secret[4], rapid_read64(key, p + 72) ^ see4);\n see5 = rapid_mix(rapid_read64(key, p + 80) ^ secret[5], rapid_read64(key, p + 88) ^ see5);\n see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);\n p += 112;\n i -= 112;\n } while (i >= 112);\n\n see3456 = see3 ^ see4 ^ see5 ^ see6;\n } else {\n see3456 = 0n;\n }\n\n if (i >= 48) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n p += 48;\n i -= 48;\n if (i >= 48) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n p += 48;\n i -= 48;\n }\n }\n\n seed ^= see1 ^ see2 ^ see3456;\n\n if (i > 16) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);\n if (i > 32) {\n seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);\n }\n }\n\n a = rapid_read64(key, p + i - 16);\n b = rapid_read64(key, p + i - 8);\n }\n\n a ^= secret[1];\n b ^= seed;\n\n return rapidhash_epilogue(a, b, secret[7], secret[1], lenBI);\n}\n\n// ---\n\n/**\n * Calculate a 64-bit hash value of the given message.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.\n */\nexport function rapidhash_v2_2(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint {\n const {seed, rapidMumBehaviour} = validateOptions(options, RAPID_SEED);\n const {rapid_mix, rapidhash_epilogue} = rapidMumImplementations[rapidMumBehaviour];\n\n return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_v2_2_fast(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogue_fast);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_v2_2_protected(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v2_2_internal(\n toDataView(message),\n seed,\n rapid_secret,\n rapid_mix_protected,\n rapidhash_epilogue_protected,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AAG,MAAMC,eAAc,gBAAgB,uBAAuB;AACjH;AAUO,SAAS,yBACd,SACA,SACQ;AACR,QAAM,EAAC,KAAI,IAAI,gBAAgB,SAASD,WAAU;AAElD,SAAO;AAAA,IACL,WAAW,OAAO;AAAA,IAClB;AAAA,IACAC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["RAPID_SEED","rapid_secret","RAPID_SEED","rapid_secret","RAPID_SEED","rapid_secret"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/common.ts","../src/common_v2.ts","../src/v3.0/common_v3.ts","../src/v3.0/rapidhash_v3.0.ts"],"sourcesContent":["export * from './v3.0/rapidhash_v3.0';\n","export type RapidMix = (a: bigint, b: bigint) => bigint;\nexport type RapidhashEpilogue = (a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint) => bigint;\n\nexport function rapid_mix_fast(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n);\n}\n\nexport function rapidhash_epilogue_fast(a: bigint, b: bigint, secretA: bigint, secretB: bigint, len: bigint): bigint {\n const m0 = a * b;\n const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * ((m0 >> 64n) ^ secretB);\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n);\n}\n\nexport function rapid_mix_protected(a: bigint, b: bigint): bigint {\n const m = a * b;\n return BigInt.asUintN(64, m) ^ (m >> 64n) ^ a ^ b;\n}\n\nexport function rapidhash_epilogue_protected(\n a0: bigint,\n b0: bigint,\n secretA: bigint,\n secretB: bigint,\n len: bigint,\n): bigint {\n const m0 = a0 * b0;\n const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;\n const b1 = (m0 >> 64n) ^ secretB ^ b0;\n const m1 = a1 * b1;\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n) ^ a1 ^ b1;\n}\n\n// ---\n\nconst read32x2Buffer = new Uint8Array(8);\nconst read32x2View = new DataView(read32x2Buffer.buffer);\n\nexport function rapid_read32x2(buf: DataView, offset1: number, offset2: number): bigint {\n read32x2View.setUint32(4, buf.getUint32(offset1, true), true);\n read32x2View.setUint32(0, buf.getUint32(offset2, true), true);\n return read32x2View.getBigUint64(0, true);\n}\n\nconst read32Buffer = new Uint8Array(8);\nconst read32View = new DataView(read32Buffer.buffer);\n\nexport function rapid_read32(buf: DataView, offset: number): bigint {\n read32View.setUint32(0, buf.getUint32(offset, true), true);\n return read32View.getBigUint64(0, true);\n}\n\nexport function rapid_read64(buf: DataView, offset: number): bigint {\n return buf.getBigUint64(offset, true);\n}\n\nconst readSmallBuffer = new Uint8Array(8);\nconst readSmallView = new DataView(readSmallBuffer.buffer);\n\nexport function rapid_readSmall(buf: DataView, offset: number, k: number): bigint {\n readSmallBuffer[7] = buf.getUint8(offset);\n readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));\n readSmallBuffer[0] = buf.getUint8(offset + k - 1);\n return readSmallView.getBigUint64(0, true);\n}\n\nconst readBytesBuffer = new Uint8Array(8);\nconst readBytesView = new DataView(readBytesBuffer.buffer);\n\nexport function rapid_readBytes(buf: DataView, offset1: number, offset2: number): bigint {\n readBytesBuffer[0] = buf.getUint8(offset2);\n readBytesBuffer[7] = buf.getUint8(offset1);\n return readBytesView.getBigUint64(0, true);\n}\n\n// ---\n\nconst textEncoder = new TextEncoder();\nconst utf8BufferSize = 2048;\nconst stringLengthThresholdToUseBuffer = utf8BufferSize / 3;\nconst utf8Buffer = new Uint8Array(utf8BufferSize);\n\nexport function toDataView(message: string | Uint8Array | DataView): DataView {\n if (typeof message === 'string') {\n if (message.length <= stringLengthThresholdToUseBuffer) {\n const {written} = textEncoder.encodeInto(message, utf8Buffer);\n return new DataView(utf8Buffer.buffer, 0, written);\n }\n\n const utf8bytes = textEncoder.encode(message);\n return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);\n }\n\n if (message instanceof Uint8Array) {\n return new DataView(message.buffer, message.byteOffset, message.byteLength);\n }\n\n return message;\n}\n\n// ---\n\nexport type RapidMumBehaviour = 'fast' | 'protected';\nconst defaultRapidMumBehaviour: RapidMumBehaviour = 'fast';\n\nexport interface RapidhashOptions {\n seed: bigint;\n rapidMumBehaviour: RapidMumBehaviour;\n}\n\nexport const rapidMumImplementations: {\n [behaviour in RapidMumBehaviour]: {\n rapid_mix: RapidMix;\n rapidhash_epilogue: RapidhashEpilogue;\n };\n} = {\n fast: {\n rapid_mix: rapid_mix_fast,\n rapidhash_epilogue: rapidhash_epilogue_fast,\n },\n protected: {\n rapid_mix: rapid_mix_protected,\n rapidhash_epilogue: rapidhash_epilogue_protected,\n },\n};\n\nfunction isBigUint64(value: bigint): boolean {\n return value >= 0n && value <= 0xffff_ffff_ffff_ffffn;\n}\n\nexport function validateOptions(options: Partial<RapidhashOptions> | undefined, defaultSeed: bigint): RapidhashOptions {\n const result: RapidhashOptions = {\n seed: defaultSeed,\n rapidMumBehaviour: defaultRapidMumBehaviour,\n };\n\n if (options === undefined) {\n return result;\n }\n\n if (options.seed !== undefined) {\n if (!isBigUint64(options.seed)) {\n throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);\n }\n result.seed = options.seed;\n }\n\n if (options.rapidMumBehaviour !== undefined) {\n result.rapidMumBehaviour = options.rapidMumBehaviour;\n }\n\n return result;\n}\n","export type RapidSecret = [bigint, bigint, bigint, bigint, bigint, bigint, bigint, bigint];\n\nexport const RAPID_SEED = 0n;\nexport const rapid_secret: RapidSecret = [\n 0x2d358dccaa6c78a5n,\n 0x8bb84b93962eacc9n,\n 0x4b33a62ed433d4a3n,\n 0x4d5a2da51de1aa47n,\n 0xa0761d6478bd642fn,\n 0xe7037ed1a0b428dbn,\n 0x90ed1765281c388cn,\n 0xaaaaaaaaaaaaaaaan,\n];\n","import {rapid_mix_fast, rapid_mix_protected} from '../common';\nimport {RAPID_SEED, type RapidSecret, rapid_secret} from '../common_v2';\n\n// Default seed and secret parameters are the same as Rapidhash V2\nexport {RAPID_SEED, type RapidSecret, rapid_secret};\n\n// ---\n\nconst readSmallV3Buffer = new Uint8Array(8);\nconst readSmallV3View = new DataView(readSmallV3Buffer.buffer);\n\nexport function rapid_readSmallV3(input: DataView, len: number): bigint {\n const v = input.getUint8(0);\n readSmallV3Buffer[6] = v >> 3;\n readSmallV3Buffer[5] = v << 5;\n readSmallV3Buffer[0] = input.getUint8(len - 1);\n return readSmallV3View.getBigUint64(0, true);\n}\n\n// ---\n\nexport type RapidhashEpilogueV3 = (a: bigint, b: bigint, secret: RapidSecret, i: bigint) => bigint;\n\nexport function rapidhash_epilogueV3_fast(a: bigint, b: bigint, secret: RapidSecret, i: bigint): bigint {\n const m0 = a * b;\n const m1 = (BigInt.asUintN(64, m0) ^ secret[7]) * ((m0 >> 64n) ^ secret[1] ^ i);\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n);\n}\n\nexport function rapidhash_epilogueV3_protected(a0: bigint, b0: bigint, secret: RapidSecret, i: bigint): bigint {\n const m0 = a0 * b0;\n const a1 = BigInt.asUintN(64, m0) ^ secret[7] ^ a0;\n const b1 = (m0 >> 64n) ^ secret[1] ^ i ^ b0;\n const m1 = a1 * b1;\n return BigInt.asUintN(64, m1) ^ (m1 >> 64n) ^ a1 ^ b1;\n}\n\n// ---\n\nexport const rapidMumImplementationsV3 = {\n fast: {\n rapid_mix: rapid_mix_fast,\n rapidhash_epilogue: rapidhash_epilogueV3_fast,\n },\n protected: {\n rapid_mix: rapid_mix_protected,\n rapidhash_epilogue: rapidhash_epilogueV3_protected,\n },\n};\n","import {\n type RapidhashOptions,\n type RapidMix,\n rapid_mix_fast,\n rapid_mix_protected,\n rapid_read32,\n rapid_read64,\n toDataView,\n validateOptions,\n} from '../common';\nimport {\n RAPID_SEED,\n type RapidhashEpilogueV3,\n type RapidSecret,\n rapid_readSmallV3,\n rapid_secret,\n rapidhash_epilogueV3_fast,\n rapidhash_epilogueV3_protected,\n rapidMumImplementationsV3,\n} from './common_v3';\n\nfunction rapidhash_v3_0_internal(\n key: DataView,\n seed: bigint,\n secret: RapidSecret,\n rapid_mix: RapidMix,\n rapidhash_epilogue: RapidhashEpilogueV3,\n): bigint {\n const len = key.byteLength;\n const lenBI = BigInt(key.byteLength);\n\n seed ^= rapid_mix(seed ^ secret[2], secret[1]);\n\n let a: bigint;\n let b: bigint;\n let i = len;\n let bi: bigint | undefined;\n\n if (len <= 16) {\n bi = lenBI;\n if (len >= 4) {\n seed ^= lenBI;\n if (len >= 8) {\n const last = len - 8;\n a = rapid_read64(key, 0);\n b = rapid_read64(key, last);\n } else {\n const last = len - 4;\n a = rapid_read32(key, 0);\n b = rapid_read32(key, last);\n }\n } else if (len > 0) {\n a = rapid_readSmallV3(key, len);\n b = BigInt(key.getUint8(len >> 1));\n } else {\n a = 0n;\n b = 0n;\n }\n } else {\n let p = 0;\n\n if (i > 112) {\n let see1 = seed;\n let see2 = seed;\n let see3 = seed;\n let see4 = seed;\n let see5 = seed;\n let see6 = seed;\n\n do {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);\n see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);\n see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);\n see3 = rapid_mix(rapid_read64(key, p + 48) ^ secret[3], rapid_read64(key, p + 56) ^ see3);\n see4 = rapid_mix(rapid_read64(key, p + 64) ^ secret[4], rapid_read64(key, p + 72) ^ see4);\n see5 = rapid_mix(rapid_read64(key, p + 80) ^ secret[5], rapid_read64(key, p + 88) ^ see5);\n see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);\n p += 112;\n i -= 112;\n } while (i > 112);\n\n seed ^= see1;\n see2 ^= see3;\n see4 ^= see5;\n seed ^= see6;\n see2 ^= see4;\n seed ^= see2;\n }\n\n bi = BigInt(i);\n\n if (i > 16) {\n seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);\n if (i > 32) {\n seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);\n if (i > 48) {\n seed = rapid_mix(rapid_read64(key, p + 32) ^ secret[1], rapid_read64(key, p + 40) ^ seed);\n if (i > 64) {\n seed = rapid_mix(rapid_read64(key, p + 48) ^ secret[1], rapid_read64(key, p + 56) ^ seed);\n if (i > 80) {\n seed = rapid_mix(rapid_read64(key, p + 64) ^ secret[2], rapid_read64(key, p + 72) ^ seed);\n if (i > 96) {\n seed = rapid_mix(rapid_read64(key, p + 80) ^ secret[1], rapid_read64(key, p + 88) ^ seed);\n }\n }\n }\n }\n }\n }\n\n a = rapid_read64(key, p + i - 16) ^ bi;\n b = rapid_read64(key, p + i - 8);\n }\n\n a ^= secret[1];\n b ^= seed;\n\n return rapidhash_epilogue(a, b, secret, bi);\n}\n\n// ---\n\n/**\n * Calculate a 64-bit hash value of the given message.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n * @param options.rapidMumBehaviour {\"fast\"|\"protected\"} Alters behaviour of the rapid_mum function. Defaults to 'fast'.\n */\nexport function rapidhash(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint {\n const {seed, rapidMumBehaviour} = validateOptions(options, RAPID_SEED);\n const {rapid_mix, rapidhash_epilogue} = rapidMumImplementationsV3[rapidMumBehaviour];\n\n return rapidhash_v3_0_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_fast(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v3_0_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogueV3_fast);\n}\n\n/**\n * Calculate a 64-bit hash value of the given message.\n * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.\n *\n * @param message {string|Uint8Array|DataView} The message to be hashed.\n * @param options Options for modifying the hash calculation.\n * @param options.seed {bigint} 64-bit unsigned seed value.\n */\nexport function rapidhash_protected(\n message: string | Uint8Array | DataView,\n options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>,\n): bigint {\n const {seed} = validateOptions(options, RAPID_SEED);\n\n return rapidhash_v3_0_internal(\n toDataView(message),\n seed,\n rapid_secret,\n rapid_mix_protected,\n rapidhash_epilogueV3_protected,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,eAAe,GAAW,GAAmB;AAC3D,QAAM,IAAI,IAAI;AACd,SAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK;AACvC;AAQO,SAAS,oBAAoB,GAAW,GAAmB;AAChE,QAAM,IAAI,IAAI;AACd,SAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK,MAAO,IAAI;AAClD;AAkBA,IAAM,iBAAiB,IAAI,WAAW,CAAC;AACvC,IAAM,eAAe,IAAI,SAAS,eAAe,MAAM;AAQvD,IAAM,eAAe,IAAI,WAAW,CAAC;AACrC,IAAM,aAAa,IAAI,SAAS,aAAa,MAAM;AAE5C,SAAS,aAAa,KAAe,QAAwB;AAClE,aAAW,UAAU,GAAG,IAAI,UAAU,QAAQ,IAAI,GAAG,IAAI;AACzD,SAAO,WAAW,aAAa,GAAG,IAAI;AACxC;AAEO,SAAS,aAAa,KAAe,QAAwB;AAClE,SAAO,IAAI,aAAa,QAAQ,IAAI;AACtC;AAEA,IAAM,kBAAkB,I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