rapidhash-js 2.0.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 +12 -0
- package/README.md +115 -49
- package/lib/common-FK5Aq1u9.d.mts +7 -0
- package/lib/common-FK5Aq1u9.d.ts +7 -0
- package/lib/index.d.mts +6 -38
- package/lib/index.d.ts +6 -38
- package/lib/index.js +101 -223
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +100 -216
- 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
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/v2.2/index.ts
|
|
21
|
+
var v2_exports = {};
|
|
22
|
+
__export(v2_exports, {
|
|
23
|
+
rapidhash: () => rapidhash_v2_2,
|
|
24
|
+
rapidhash_fast: () => rapidhash_v2_2_fast,
|
|
25
|
+
rapidhash_protected: () => rapidhash_v2_2_protected
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(v2_exports);
|
|
28
|
+
|
|
29
|
+
// src/common.ts
|
|
30
|
+
function rapid_mix_fast(a, b) {
|
|
31
|
+
const m = a * b;
|
|
32
|
+
return BigInt.asUintN(64, m) ^ m >> 64n;
|
|
33
|
+
}
|
|
34
|
+
function rapidhash_epilogue_fast(a, b, secretA, secretB, len) {
|
|
35
|
+
const m0 = a * b;
|
|
36
|
+
const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * (m0 >> 64n ^ secretB);
|
|
37
|
+
return BigInt.asUintN(64, m1) ^ m1 >> 64n;
|
|
38
|
+
}
|
|
39
|
+
function rapid_mix_protected(a, b) {
|
|
40
|
+
const m = a * b;
|
|
41
|
+
return BigInt.asUintN(64, m) ^ m >> 64n ^ a ^ b;
|
|
42
|
+
}
|
|
43
|
+
function rapidhash_epilogue_protected(a0, b0, secretA, secretB, len) {
|
|
44
|
+
const m0 = a0 * b0;
|
|
45
|
+
const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;
|
|
46
|
+
const b1 = m0 >> 64n ^ secretB ^ b0;
|
|
47
|
+
const m1 = a1 * b1;
|
|
48
|
+
return BigInt.asUintN(64, m1) ^ m1 >> 64n ^ a1 ^ b1;
|
|
49
|
+
}
|
|
50
|
+
var read32x2Buffer = new Uint8Array(8);
|
|
51
|
+
var read32x2View = new DataView(read32x2Buffer.buffer);
|
|
52
|
+
var read32Buffer = new Uint8Array(8);
|
|
53
|
+
var read32View = new DataView(read32Buffer.buffer);
|
|
54
|
+
function rapid_read32(buf, offset) {
|
|
55
|
+
read32View.setUint32(0, buf.getUint32(offset, true), true);
|
|
56
|
+
return read32View.getBigUint64(0, true);
|
|
57
|
+
}
|
|
58
|
+
function rapid_read64(buf, offset) {
|
|
59
|
+
return buf.getBigUint64(offset, true);
|
|
60
|
+
}
|
|
61
|
+
var readSmallBuffer = new Uint8Array(8);
|
|
62
|
+
var readSmallView = new DataView(readSmallBuffer.buffer);
|
|
63
|
+
var readBytesBuffer = new Uint8Array(8);
|
|
64
|
+
var readBytesView = new DataView(readBytesBuffer.buffer);
|
|
65
|
+
function rapid_readBytes(buf, offset1, offset2) {
|
|
66
|
+
readBytesBuffer[0] = buf.getUint8(offset2);
|
|
67
|
+
readBytesBuffer[7] = buf.getUint8(offset1);
|
|
68
|
+
return readBytesView.getBigUint64(0, true);
|
|
69
|
+
}
|
|
70
|
+
var textEncoder = new TextEncoder();
|
|
71
|
+
var utf8BufferSize = 2048;
|
|
72
|
+
var stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
|
|
73
|
+
var utf8Buffer = new Uint8Array(utf8BufferSize);
|
|
74
|
+
function toDataView(message) {
|
|
75
|
+
if (typeof message === "string") {
|
|
76
|
+
if (message.length <= stringLengthThresholdToUseBuffer) {
|
|
77
|
+
const { written } = textEncoder.encodeInto(message, utf8Buffer);
|
|
78
|
+
return new DataView(utf8Buffer.buffer, 0, written);
|
|
79
|
+
}
|
|
80
|
+
const utf8bytes = textEncoder.encode(message);
|
|
81
|
+
return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);
|
|
82
|
+
}
|
|
83
|
+
if (message instanceof Uint8Array) {
|
|
84
|
+
return new DataView(message.buffer, message.byteOffset, message.byteLength);
|
|
85
|
+
}
|
|
86
|
+
return message;
|
|
87
|
+
}
|
|
88
|
+
var defaultRapidMumBehaviour = "fast";
|
|
89
|
+
var rapidMumImplementations = {
|
|
90
|
+
fast: {
|
|
91
|
+
rapid_mix: rapid_mix_fast,
|
|
92
|
+
rapidhash_epilogue: rapidhash_epilogue_fast
|
|
93
|
+
},
|
|
94
|
+
protected: {
|
|
95
|
+
rapid_mix: rapid_mix_protected,
|
|
96
|
+
rapidhash_epilogue: rapidhash_epilogue_protected
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
function isBigUint64(value) {
|
|
100
|
+
return value >= 0n && value <= 0xffffffffffffffffn;
|
|
101
|
+
}
|
|
102
|
+
function validateOptions(options, defaultSeed) {
|
|
103
|
+
const result = {
|
|
104
|
+
seed: defaultSeed,
|
|
105
|
+
rapidMumBehaviour: defaultRapidMumBehaviour
|
|
106
|
+
};
|
|
107
|
+
if (options === void 0) {
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
if (options.seed !== void 0) {
|
|
111
|
+
if (!isBigUint64(options.seed)) {
|
|
112
|
+
throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);
|
|
113
|
+
}
|
|
114
|
+
result.seed = options.seed;
|
|
115
|
+
}
|
|
116
|
+
if (options.rapidMumBehaviour !== void 0) {
|
|
117
|
+
result.rapidMumBehaviour = options.rapidMumBehaviour;
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/common_v2.ts
|
|
123
|
+
var RAPID_SEED = 0n;
|
|
124
|
+
var rapid_secret = [
|
|
125
|
+
0x2d358dccaa6c78a5n,
|
|
126
|
+
0x8bb84b93962eacc9n,
|
|
127
|
+
0x4b33a62ed433d4a3n,
|
|
128
|
+
0x4d5a2da51de1aa47n,
|
|
129
|
+
0xa0761d6478bd642fn,
|
|
130
|
+
0xe7037ed1a0b428dbn,
|
|
131
|
+
0x90ed1765281c388cn,
|
|
132
|
+
0xaaaaaaaaaaaaaaaan
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
// src/v2.2/rapidhash_v2.2.ts
|
|
136
|
+
function rapidhash_v2_2_internal(key, seed, secret, rapid_mix, rapidhash_epilogue) {
|
|
137
|
+
const len = key.byteLength;
|
|
138
|
+
const lenBI = BigInt(key.byteLength);
|
|
139
|
+
seed ^= rapid_mix(seed ^ secret[2], secret[1]) ^ lenBI;
|
|
140
|
+
let a;
|
|
141
|
+
let b;
|
|
142
|
+
if (len <= 16) {
|
|
143
|
+
if (len >= 4) {
|
|
144
|
+
if (len >= 8) {
|
|
145
|
+
const last = len - 8;
|
|
146
|
+
a = rapid_read64(key, 0);
|
|
147
|
+
b = rapid_read64(key, last);
|
|
148
|
+
} else {
|
|
149
|
+
const last = len - 4;
|
|
150
|
+
a = rapid_read32(key, 0);
|
|
151
|
+
b = rapid_read32(key, last);
|
|
152
|
+
}
|
|
153
|
+
} else if (len > 0) {
|
|
154
|
+
a = rapid_readBytes(key, 0, len - 1);
|
|
155
|
+
b = BigInt(key.getUint8(len >> 1));
|
|
156
|
+
} else {
|
|
157
|
+
a = 0n;
|
|
158
|
+
b = 0n;
|
|
159
|
+
}
|
|
160
|
+
} else if (len <= 64) {
|
|
161
|
+
seed = rapid_mix(rapid_read64(key, 0) ^ secret[0], rapid_read64(key, 8) ^ seed);
|
|
162
|
+
if (len > 32) {
|
|
163
|
+
seed = rapid_mix(rapid_read64(key, 16) ^ secret[1], rapid_read64(key, 24) ^ seed);
|
|
164
|
+
if (len > 48) {
|
|
165
|
+
seed = rapid_mix(rapid_read64(key, 32) ^ secret[1], rapid_read64(key, 40) ^ seed);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
a = rapid_read64(key, len - 16);
|
|
169
|
+
b = rapid_read64(key, len - 8);
|
|
170
|
+
} else {
|
|
171
|
+
let i = len;
|
|
172
|
+
let p = 0;
|
|
173
|
+
let see1 = seed;
|
|
174
|
+
let see2 = seed;
|
|
175
|
+
let see3456;
|
|
176
|
+
if (i >= 112) {
|
|
177
|
+
let see3 = seed;
|
|
178
|
+
let see4 = seed;
|
|
179
|
+
let see5 = seed;
|
|
180
|
+
let see6 = seed;
|
|
181
|
+
do {
|
|
182
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
183
|
+
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
184
|
+
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
185
|
+
see3 = rapid_mix(rapid_read64(key, p + 48) ^ secret[3], rapid_read64(key, p + 56) ^ see3);
|
|
186
|
+
see4 = rapid_mix(rapid_read64(key, p + 64) ^ secret[4], rapid_read64(key, p + 72) ^ see4);
|
|
187
|
+
see5 = rapid_mix(rapid_read64(key, p + 80) ^ secret[5], rapid_read64(key, p + 88) ^ see5);
|
|
188
|
+
see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);
|
|
189
|
+
p += 112;
|
|
190
|
+
i -= 112;
|
|
191
|
+
} while (i >= 112);
|
|
192
|
+
see3456 = see3 ^ see4 ^ see5 ^ see6;
|
|
193
|
+
} else {
|
|
194
|
+
see3456 = 0n;
|
|
195
|
+
}
|
|
196
|
+
if (i >= 48) {
|
|
197
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
198
|
+
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
199
|
+
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
200
|
+
p += 48;
|
|
201
|
+
i -= 48;
|
|
202
|
+
if (i >= 48) {
|
|
203
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
204
|
+
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
205
|
+
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
206
|
+
p += 48;
|
|
207
|
+
i -= 48;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
seed ^= see1 ^ see2 ^ see3456;
|
|
211
|
+
if (i > 16) {
|
|
212
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);
|
|
213
|
+
if (i > 32) {
|
|
214
|
+
seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
a = rapid_read64(key, p + i - 16);
|
|
218
|
+
b = rapid_read64(key, p + i - 8);
|
|
219
|
+
}
|
|
220
|
+
a ^= secret[1];
|
|
221
|
+
b ^= seed;
|
|
222
|
+
return rapidhash_epilogue(a, b, secret[7], secret[1], lenBI);
|
|
223
|
+
}
|
|
224
|
+
function rapidhash_v2_2(message, options) {
|
|
225
|
+
const { seed, rapidMumBehaviour } = validateOptions(options, RAPID_SEED);
|
|
226
|
+
const { rapid_mix, rapidhash_epilogue } = rapidMumImplementations[rapidMumBehaviour];
|
|
227
|
+
return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);
|
|
228
|
+
}
|
|
229
|
+
function rapidhash_v2_2_fast(message, options) {
|
|
230
|
+
const { seed } = validateOptions(options, RAPID_SEED);
|
|
231
|
+
return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogue_fast);
|
|
232
|
+
}
|
|
233
|
+
function rapidhash_v2_2_protected(message, options) {
|
|
234
|
+
const { seed } = validateOptions(options, RAPID_SEED);
|
|
235
|
+
return rapidhash_v2_2_internal(
|
|
236
|
+
toDataView(message),
|
|
237
|
+
seed,
|
|
238
|
+
rapid_secret,
|
|
239
|
+
rapid_mix_protected,
|
|
240
|
+
rapidhash_epilogue_protected
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
244
|
+
0 && (module.exports = {
|
|
245
|
+
rapidhash,
|
|
246
|
+
rapidhash_fast,
|
|
247
|
+
rapidhash_protected
|
|
248
|
+
});
|
|
249
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/v2.2/index.ts","../../src/common.ts","../../src/common_v2.ts","../../src/v2.2/rapidhash_v2.2.ts"],"sourcesContent":["import {\n rapidhash_v2_2 as rapidhash,\n rapidhash_v2_2_fast as rapidhash_fast,\n rapidhash_v2_2_protected as rapidhash_protected,\n} from './rapidhash_v2.2';\n\nexport {rapidhash, rapidhash_fast, rapidhash_protected};\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 {\n type RapidhashEpilogue,\n type RapidhashOptions,\n type RapidMix,\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 rapidMumImplementations,\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;;;ACGO,SAAS,eAAe,GAAW,GAAmB;AAC3D,QAAM,IAAI,IAAI;AACd,SAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK;AACvC;AAEO,SAAS,wBAAwB,GAAW,GAAW,SAAiB,SAAiB,KAAqB;AACnH,QAAM,KAAK,IAAI;AACf,QAAM,MAAM,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,QAAS,MAAM,MAAO;AACrE,SAAO,OAAO,QAAQ,IAAI,EAAE,IAAK,MAAM;AACzC;AAEO,SAAS,oBAAoB,GAAW,GAAmB;AAChE,QAAM,IAAI,IAAI;AACd,SAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK,MAAO,IAAI;AAClD;AAEO,SAAS,6BACd,IACA,IACA,SACA,SACA,KACQ;AACR,QAAM,KAAK,KAAK;AAChB,QAAM,KAAK,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,MAAM;AACpD,QAAM,KAAM,MAAM,MAAO,UAAU;AACnC,QAAM,KAAK,KAAK;AAChB,SAAO,OAAO,QAAQ,IAAI,EAAE,IAAK,MAAM,MAAO,KAAK;AACrD;AAIA,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,SAA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F;AAEA,QAAI,aAAa,KAAK,IAAI,IAAI,EAAE;AAChC,QAAI,aAAa,KAAK,IAAI,IAAI,CAAC;AAAA,EACjC;AAEA,OAAK,OAAO,CAAC;AACb,OAAK;AAEL,SAAO,mBAAmB,GAAG,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,KAAK;AAC7D;AAYO,SAAS,eAAe,SAAyC,SAA6C;AACnH,QAAM,EAAC,MAAM,kBAAiB,IAAI,gBAAgB,SAAS,UAAU;AACrE,QAAM,EAAC,WAAW,mBAAkB,IAAI,wBAAwB,iBAAiB;AAEjF,SAAO,wBAAwB,WAAW,OAAO,GAAG,MAAM,cAAc,WAAW,kBAAkB;AACvG;AAUO,SAAS,oBACd,SACA,SACQ;AACR,QAAM,EAAC,KAAI,IAAI,gBAAgB,SAAS,UAAU;AAElD,SAAO,wBAAwB,WAAW,OAAO,GAAG,MAAM,cAAc,gBAAgB,uBAAuB;AACjH;AAUO,SAAS,yBACd,SACA,SACQ;AACR,QAAM,EAAC,KAAI,IAAI,gBAAgB,SAAS,UAAU;AAElD,SAAO;AAAA,IACL,WAAW,OAAO;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// src/common.ts
|
|
2
|
+
function rapid_mix_fast(a, b) {
|
|
3
|
+
const m = a * b;
|
|
4
|
+
return BigInt.asUintN(64, m) ^ m >> 64n;
|
|
5
|
+
}
|
|
6
|
+
function rapidhash_epilogue_fast(a, b, secretA, secretB, len) {
|
|
7
|
+
const m0 = a * b;
|
|
8
|
+
const m1 = (BigInt.asUintN(64, m0) ^ secretA ^ len) * (m0 >> 64n ^ secretB);
|
|
9
|
+
return BigInt.asUintN(64, m1) ^ m1 >> 64n;
|
|
10
|
+
}
|
|
11
|
+
function rapid_mix_protected(a, b) {
|
|
12
|
+
const m = a * b;
|
|
13
|
+
return BigInt.asUintN(64, m) ^ m >> 64n ^ a ^ b;
|
|
14
|
+
}
|
|
15
|
+
function rapidhash_epilogue_protected(a0, b0, secretA, secretB, len) {
|
|
16
|
+
const m0 = a0 * b0;
|
|
17
|
+
const a1 = BigInt.asUintN(64, m0) ^ secretA ^ len ^ a0;
|
|
18
|
+
const b1 = m0 >> 64n ^ secretB ^ b0;
|
|
19
|
+
const m1 = a1 * b1;
|
|
20
|
+
return BigInt.asUintN(64, m1) ^ m1 >> 64n ^ a1 ^ b1;
|
|
21
|
+
}
|
|
22
|
+
var read32x2Buffer = new Uint8Array(8);
|
|
23
|
+
var read32x2View = new DataView(read32x2Buffer.buffer);
|
|
24
|
+
var read32Buffer = new Uint8Array(8);
|
|
25
|
+
var read32View = new DataView(read32Buffer.buffer);
|
|
26
|
+
function rapid_read32(buf, offset) {
|
|
27
|
+
read32View.setUint32(0, buf.getUint32(offset, true), true);
|
|
28
|
+
return read32View.getBigUint64(0, true);
|
|
29
|
+
}
|
|
30
|
+
function rapid_read64(buf, offset) {
|
|
31
|
+
return buf.getBigUint64(offset, true);
|
|
32
|
+
}
|
|
33
|
+
var readSmallBuffer = new Uint8Array(8);
|
|
34
|
+
var readSmallView = new DataView(readSmallBuffer.buffer);
|
|
35
|
+
var readBytesBuffer = new Uint8Array(8);
|
|
36
|
+
var readBytesView = new DataView(readBytesBuffer.buffer);
|
|
37
|
+
function rapid_readBytes(buf, offset1, offset2) {
|
|
38
|
+
readBytesBuffer[0] = buf.getUint8(offset2);
|
|
39
|
+
readBytesBuffer[7] = buf.getUint8(offset1);
|
|
40
|
+
return readBytesView.getBigUint64(0, true);
|
|
41
|
+
}
|
|
42
|
+
var textEncoder = new TextEncoder();
|
|
43
|
+
var utf8BufferSize = 2048;
|
|
44
|
+
var stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
|
|
45
|
+
var utf8Buffer = new Uint8Array(utf8BufferSize);
|
|
46
|
+
function toDataView(message) {
|
|
47
|
+
if (typeof message === "string") {
|
|
48
|
+
if (message.length <= stringLengthThresholdToUseBuffer) {
|
|
49
|
+
const { written } = textEncoder.encodeInto(message, utf8Buffer);
|
|
50
|
+
return new DataView(utf8Buffer.buffer, 0, written);
|
|
51
|
+
}
|
|
52
|
+
const utf8bytes = textEncoder.encode(message);
|
|
53
|
+
return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);
|
|
54
|
+
}
|
|
55
|
+
if (message instanceof Uint8Array) {
|
|
56
|
+
return new DataView(message.buffer, message.byteOffset, message.byteLength);
|
|
57
|
+
}
|
|
58
|
+
return message;
|
|
59
|
+
}
|
|
60
|
+
var defaultRapidMumBehaviour = "fast";
|
|
61
|
+
var rapidMumImplementations = {
|
|
62
|
+
fast: {
|
|
63
|
+
rapid_mix: rapid_mix_fast,
|
|
64
|
+
rapidhash_epilogue: rapidhash_epilogue_fast
|
|
65
|
+
},
|
|
66
|
+
protected: {
|
|
67
|
+
rapid_mix: rapid_mix_protected,
|
|
68
|
+
rapidhash_epilogue: rapidhash_epilogue_protected
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function isBigUint64(value) {
|
|
72
|
+
return value >= 0n && value <= 0xffffffffffffffffn;
|
|
73
|
+
}
|
|
74
|
+
function validateOptions(options, defaultSeed) {
|
|
75
|
+
const result = {
|
|
76
|
+
seed: defaultSeed,
|
|
77
|
+
rapidMumBehaviour: defaultRapidMumBehaviour
|
|
78
|
+
};
|
|
79
|
+
if (options === void 0) {
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
if (options.seed !== void 0) {
|
|
83
|
+
if (!isBigUint64(options.seed)) {
|
|
84
|
+
throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);
|
|
85
|
+
}
|
|
86
|
+
result.seed = options.seed;
|
|
87
|
+
}
|
|
88
|
+
if (options.rapidMumBehaviour !== void 0) {
|
|
89
|
+
result.rapidMumBehaviour = options.rapidMumBehaviour;
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// src/common_v2.ts
|
|
95
|
+
var RAPID_SEED = 0n;
|
|
96
|
+
var rapid_secret = [
|
|
97
|
+
0x2d358dccaa6c78a5n,
|
|
98
|
+
0x8bb84b93962eacc9n,
|
|
99
|
+
0x4b33a62ed433d4a3n,
|
|
100
|
+
0x4d5a2da51de1aa47n,
|
|
101
|
+
0xa0761d6478bd642fn,
|
|
102
|
+
0xe7037ed1a0b428dbn,
|
|
103
|
+
0x90ed1765281c388cn,
|
|
104
|
+
0xaaaaaaaaaaaaaaaan
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
// src/v2.2/rapidhash_v2.2.ts
|
|
108
|
+
function rapidhash_v2_2_internal(key, seed, secret, rapid_mix, rapidhash_epilogue) {
|
|
109
|
+
const len = key.byteLength;
|
|
110
|
+
const lenBI = BigInt(key.byteLength);
|
|
111
|
+
seed ^= rapid_mix(seed ^ secret[2], secret[1]) ^ lenBI;
|
|
112
|
+
let a;
|
|
113
|
+
let b;
|
|
114
|
+
if (len <= 16) {
|
|
115
|
+
if (len >= 4) {
|
|
116
|
+
if (len >= 8) {
|
|
117
|
+
const last = len - 8;
|
|
118
|
+
a = rapid_read64(key, 0);
|
|
119
|
+
b = rapid_read64(key, last);
|
|
120
|
+
} else {
|
|
121
|
+
const last = len - 4;
|
|
122
|
+
a = rapid_read32(key, 0);
|
|
123
|
+
b = rapid_read32(key, last);
|
|
124
|
+
}
|
|
125
|
+
} else if (len > 0) {
|
|
126
|
+
a = rapid_readBytes(key, 0, len - 1);
|
|
127
|
+
b = BigInt(key.getUint8(len >> 1));
|
|
128
|
+
} else {
|
|
129
|
+
a = 0n;
|
|
130
|
+
b = 0n;
|
|
131
|
+
}
|
|
132
|
+
} else if (len <= 64) {
|
|
133
|
+
seed = rapid_mix(rapid_read64(key, 0) ^ secret[0], rapid_read64(key, 8) ^ seed);
|
|
134
|
+
if (len > 32) {
|
|
135
|
+
seed = rapid_mix(rapid_read64(key, 16) ^ secret[1], rapid_read64(key, 24) ^ seed);
|
|
136
|
+
if (len > 48) {
|
|
137
|
+
seed = rapid_mix(rapid_read64(key, 32) ^ secret[1], rapid_read64(key, 40) ^ seed);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
a = rapid_read64(key, len - 16);
|
|
141
|
+
b = rapid_read64(key, len - 8);
|
|
142
|
+
} else {
|
|
143
|
+
let i = len;
|
|
144
|
+
let p = 0;
|
|
145
|
+
let see1 = seed;
|
|
146
|
+
let see2 = seed;
|
|
147
|
+
let see3456;
|
|
148
|
+
if (i >= 112) {
|
|
149
|
+
let see3 = seed;
|
|
150
|
+
let see4 = seed;
|
|
151
|
+
let see5 = seed;
|
|
152
|
+
let see6 = seed;
|
|
153
|
+
do {
|
|
154
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
155
|
+
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
156
|
+
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
157
|
+
see3 = rapid_mix(rapid_read64(key, p + 48) ^ secret[3], rapid_read64(key, p + 56) ^ see3);
|
|
158
|
+
see4 = rapid_mix(rapid_read64(key, p + 64) ^ secret[4], rapid_read64(key, p + 72) ^ see4);
|
|
159
|
+
see5 = rapid_mix(rapid_read64(key, p + 80) ^ secret[5], rapid_read64(key, p + 88) ^ see5);
|
|
160
|
+
see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);
|
|
161
|
+
p += 112;
|
|
162
|
+
i -= 112;
|
|
163
|
+
} while (i >= 112);
|
|
164
|
+
see3456 = see3 ^ see4 ^ see5 ^ see6;
|
|
165
|
+
} else {
|
|
166
|
+
see3456 = 0n;
|
|
167
|
+
}
|
|
168
|
+
if (i >= 48) {
|
|
169
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
170
|
+
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
171
|
+
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
172
|
+
p += 48;
|
|
173
|
+
i -= 48;
|
|
174
|
+
if (i >= 48) {
|
|
175
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
|
|
176
|
+
see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
|
|
177
|
+
see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
|
|
178
|
+
p += 48;
|
|
179
|
+
i -= 48;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
seed ^= see1 ^ see2 ^ see3456;
|
|
183
|
+
if (i > 16) {
|
|
184
|
+
seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);
|
|
185
|
+
if (i > 32) {
|
|
186
|
+
seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
a = rapid_read64(key, p + i - 16);
|
|
190
|
+
b = rapid_read64(key, p + i - 8);
|
|
191
|
+
}
|
|
192
|
+
a ^= secret[1];
|
|
193
|
+
b ^= seed;
|
|
194
|
+
return rapidhash_epilogue(a, b, secret[7], secret[1], lenBI);
|
|
195
|
+
}
|
|
196
|
+
function rapidhash_v2_2(message, options) {
|
|
197
|
+
const { seed, rapidMumBehaviour } = validateOptions(options, RAPID_SEED);
|
|
198
|
+
const { rapid_mix, rapidhash_epilogue } = rapidMumImplementations[rapidMumBehaviour];
|
|
199
|
+
return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret, rapid_mix, rapidhash_epilogue);
|
|
200
|
+
}
|
|
201
|
+
function rapidhash_v2_2_fast(message, options) {
|
|
202
|
+
const { seed } = validateOptions(options, RAPID_SEED);
|
|
203
|
+
return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret, rapid_mix_fast, rapidhash_epilogue_fast);
|
|
204
|
+
}
|
|
205
|
+
function rapidhash_v2_2_protected(message, options) {
|
|
206
|
+
const { seed } = validateOptions(options, RAPID_SEED);
|
|
207
|
+
return rapidhash_v2_2_internal(
|
|
208
|
+
toDataView(message),
|
|
209
|
+
seed,
|
|
210
|
+
rapid_secret,
|
|
211
|
+
rapid_mix_protected,
|
|
212
|
+
rapidhash_epilogue_protected
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
export {
|
|
216
|
+
rapidhash_v2_2 as rapidhash,
|
|
217
|
+
rapidhash_v2_2_fast as rapidhash_fast,
|
|
218
|
+
rapidhash_v2_2_protected as rapidhash_protected
|
|
219
|
+
};
|
|
220
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common.ts","../../src/common_v2.ts","../../src/v2.2/rapidhash_v2.2.ts"],"sourcesContent":["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 {\n type RapidhashEpilogue,\n type RapidhashOptions,\n type RapidMix,\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 rapidMumImplementations,\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":";AAGO,SAAS,eAAe,GAAW,GAAmB;AAC3D,QAAM,IAAI,IAAI;AACd,SAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK;AACvC;AAEO,SAAS,wBAAwB,GAAW,GAAW,SAAiB,SAAiB,KAAqB;AACnH,QAAM,KAAK,IAAI;AACf,QAAM,MAAM,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,QAAS,MAAM,MAAO;AACrE,SAAO,OAAO,QAAQ,IAAI,EAAE,IAAK,MAAM;AACzC;AAEO,SAAS,oBAAoB,GAAW,GAAmB;AAChE,QAAM,IAAI,IAAI;AACd,SAAO,OAAO,QAAQ,IAAI,CAAC,IAAK,KAAK,MAAO,IAAI;AAClD;AAEO,SAAS,6BACd,IACA,IACA,SACA,SACA,KACQ;AACR,QAAM,KAAK,KAAK;AAChB,QAAM,KAAK,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,MAAM;AACpD,QAAM,KAAM,MAAM,MAAO,UAAU;AACnC,QAAM,KAAK,KAAK;AAChB,SAAO,OAAO,QAAQ,IAAI,EAAE,IAAK,MAAM,MAAO,KAAK;AACrD;AAIA,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,kBAAk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b,OAAK;AAEL,SAAO,mBAAmB,GAAG,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,KAAK;AAC7D;AAYO,SAAS,eAAe,SAAyC,SAA6C;AACnH,QAAM,EAAC,MAAM,kBAAiB,IAAI,gBAAgB,SAAS,UAAU;AACrE,QAAM,EAAC,WAAW,mBAAkB,IAAI,wBAAwB,iBAAiB;AAEjF,SAAO,wBAAwB,WAAW,OAAO,GAAG,MAAM,cAAc,WAAW,kBAAkB;AACvG;AAUO,SAAS,oBACd,SACA,SACQ;AACR,QAAM,EAAC,KAAI,IAAI,gBAAgB,SAAS,UAAU;AAElD,SAAO,wBAAwB,WAAW,OAAO,GAAG,MAAM,cAAc,gBAAgB,uBAAuB;AACjH;AAUO,SAAS,yBACd,SACA,SACQ;AACR,QAAM,EAAC,KAAI,IAAI,gBAAgB,SAAS,UAAU;AAElD,SAAO;AAAA,IACL,WAAW,OAAO;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export { rapidhash, rapidhash_fast, rapidhash_protected } from '../index.mjs';
|
|
2
|
+
import { R as RapidhashOptions } from '../common-FK5Aq1u9.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculate a 64-bit hash value of the given message using the Micro variant.
|
|
6
|
+
* This variant uses 80-byte loop blocks for optimized performance characteristics.
|
|
7
|
+
*
|
|
8
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
9
|
+
* @param options Options for modifying the hash calculation.
|
|
10
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
11
|
+
* @param options.rapidMumBehaviour {"fast"|"protected"} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
|
|
12
|
+
*/
|
|
13
|
+
declare function rapidhashMicro(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Calculate a 64-bit hash value of the given message using the Micro variant.
|
|
16
|
+
* This function is equivalent to rapidhashMicro() with options.rapidMumBehaviour set to 'fast'.
|
|
17
|
+
*
|
|
18
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
19
|
+
* @param options Options for modifying the hash calculation.
|
|
20
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
21
|
+
*/
|
|
22
|
+
declare function rapidhashMicro_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
23
|
+
/**
|
|
24
|
+
* Calculate a 64-bit hash value of the given message using the Micro variant.
|
|
25
|
+
* This function is equivalent to rapidhashMicro() with options.rapidMumBehaviour set to 'protected'.
|
|
26
|
+
*
|
|
27
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
28
|
+
* @param options Options for modifying the hash calculation.
|
|
29
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
30
|
+
*/
|
|
31
|
+
declare function rapidhashMicro_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Calculate a 64-bit hash value of the given message using the Nano variant.
|
|
35
|
+
* This variant uses 48-byte loop blocks for optimized performance characteristics.
|
|
36
|
+
*
|
|
37
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
38
|
+
* @param options Options for modifying the hash calculation.
|
|
39
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
40
|
+
* @param options.rapidMumBehaviour {"fast"|"protected"} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
|
|
41
|
+
*/
|
|
42
|
+
declare function rapidhashNano(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
|
|
43
|
+
/**
|
|
44
|
+
* Calculate a 64-bit hash value of the given message using the Nano variant.
|
|
45
|
+
* This function is equivalent to rapidhashNano() with options.rapidMumBehaviour set to 'fast'.
|
|
46
|
+
*
|
|
47
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
48
|
+
* @param options Options for modifying the hash calculation.
|
|
49
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
50
|
+
*/
|
|
51
|
+
declare function rapidhashNano_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
52
|
+
/**
|
|
53
|
+
* Calculate a 64-bit hash value of the given message using the Nano variant.
|
|
54
|
+
* This function is equivalent to rapidhashNano() with options.rapidMumBehaviour set to 'protected'.
|
|
55
|
+
*
|
|
56
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
57
|
+
* @param options Options for modifying the hash calculation.
|
|
58
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
59
|
+
*/
|
|
60
|
+
declare function rapidhashNano_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
61
|
+
|
|
62
|
+
export { rapidhashMicro, rapidhashMicro_fast, rapidhashMicro_protected, rapidhashNano, rapidhashNano_fast, rapidhashNano_protected };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export { rapidhash, rapidhash_fast, rapidhash_protected } from '../index.js';
|
|
2
|
+
import { R as RapidhashOptions } from '../common-FK5Aq1u9.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculate a 64-bit hash value of the given message using the Micro variant.
|
|
6
|
+
* This variant uses 80-byte loop blocks for optimized performance characteristics.
|
|
7
|
+
*
|
|
8
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
9
|
+
* @param options Options for modifying the hash calculation.
|
|
10
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
11
|
+
* @param options.rapidMumBehaviour {"fast"|"protected"} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
|
|
12
|
+
*/
|
|
13
|
+
declare function rapidhashMicro(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* Calculate a 64-bit hash value of the given message using the Micro variant.
|
|
16
|
+
* This function is equivalent to rapidhashMicro() with options.rapidMumBehaviour set to 'fast'.
|
|
17
|
+
*
|
|
18
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
19
|
+
* @param options Options for modifying the hash calculation.
|
|
20
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
21
|
+
*/
|
|
22
|
+
declare function rapidhashMicro_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
23
|
+
/**
|
|
24
|
+
* Calculate a 64-bit hash value of the given message using the Micro variant.
|
|
25
|
+
* This function is equivalent to rapidhashMicro() with options.rapidMumBehaviour set to 'protected'.
|
|
26
|
+
*
|
|
27
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
28
|
+
* @param options Options for modifying the hash calculation.
|
|
29
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
30
|
+
*/
|
|
31
|
+
declare function rapidhashMicro_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Calculate a 64-bit hash value of the given message using the Nano variant.
|
|
35
|
+
* This variant uses 48-byte loop blocks for optimized performance characteristics.
|
|
36
|
+
*
|
|
37
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
38
|
+
* @param options Options for modifying the hash calculation.
|
|
39
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
40
|
+
* @param options.rapidMumBehaviour {"fast"|"protected"} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
|
|
41
|
+
*/
|
|
42
|
+
declare function rapidhashNano(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
|
|
43
|
+
/**
|
|
44
|
+
* Calculate a 64-bit hash value of the given message using the Nano variant.
|
|
45
|
+
* This function is equivalent to rapidhashNano() with options.rapidMumBehaviour set to 'fast'.
|
|
46
|
+
*
|
|
47
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
48
|
+
* @param options Options for modifying the hash calculation.
|
|
49
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
50
|
+
*/
|
|
51
|
+
declare function rapidhashNano_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
52
|
+
/**
|
|
53
|
+
* Calculate a 64-bit hash value of the given message using the Nano variant.
|
|
54
|
+
* This function is equivalent to rapidhashNano() with options.rapidMumBehaviour set to 'protected'.
|
|
55
|
+
*
|
|
56
|
+
* @param message {string|Uint8Array|DataView} The message to be hashed.
|
|
57
|
+
* @param options Options for modifying the hash calculation.
|
|
58
|
+
* @param options.seed {bigint} 64-bit unsigned seed value.
|
|
59
|
+
*/
|
|
60
|
+
declare function rapidhashNano_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
|
|
61
|
+
|
|
62
|
+
export { rapidhashMicro, rapidhashMicro_fast, rapidhashMicro_protected, rapidhashNano, rapidhashNano_fast, rapidhashNano_protected };
|