rapidhash-js 2.2.0 → 3.0.1

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +100 -53
  3. package/lib/common.d.mts +7 -0
  4. package/lib/common.d.ts +7 -0
  5. package/lib/common.js +167 -0
  6. package/lib/common.js.map +1 -0
  7. package/lib/common.mjs +96 -0
  8. package/lib/common.mjs.map +1 -0
  9. package/lib/common_v2.js +26 -0
  10. package/lib/common_v2.js.map +1 -0
  11. package/lib/common_v2.mjs +15 -0
  12. package/lib/common_v2.mjs.map +1 -0
  13. package/lib/index.d.mts +2 -91
  14. package/lib/index.d.ts +2 -91
  15. package/lib/index.js +11 -467
  16. package/lib/index.mjs +1 -429
  17. package/lib/v1.0/index.d.mts +30 -0
  18. package/lib/v1.0/index.d.ts +30 -0
  19. package/lib/v1.0/index.js +106 -0
  20. package/lib/v1.0/index.js.map +1 -0
  21. package/lib/v1.0/index.mjs +103 -0
  22. package/lib/v1.0/index.mjs.map +1 -0
  23. package/lib/v2.0/index.d.mts +30 -0
  24. package/lib/v2.0/index.d.ts +30 -0
  25. package/lib/v2.0/index.js +128 -0
  26. package/lib/v2.0/index.js.map +1 -0
  27. package/lib/v2.0/index.mjs +125 -0
  28. package/lib/v2.0/index.mjs.map +1 -0
  29. package/lib/v2.2/index.d.mts +30 -0
  30. package/lib/v2.2/index.d.ts +30 -0
  31. package/lib/v2.2/index.js +128 -0
  32. package/lib/v2.2/index.js.map +1 -0
  33. package/lib/v2.2/index.mjs +125 -0
  34. package/lib/v2.2/index.mjs.map +1 -0
  35. package/lib/v3.0/index.d.mts +86 -0
  36. package/lib/v3.0/index.d.ts +86 -0
  37. package/lib/v3.0/index.js +11 -0
  38. package/lib/v3.0/index.mjs +1 -0
  39. package/lib/v3.0.js +407 -0
  40. package/lib/v3.0.js.map +1 -0
  41. package/lib/v3.0.mjs +354 -0
  42. package/lib/v3.0.mjs.map +1 -0
  43. package/package.json +23 -15
  44. package/lib/index.js.map +0 -1
  45. package/lib/index.mjs.map +0 -1
package/lib/index.d.mts CHANGED
@@ -1,91 +1,2 @@
1
- type RapidMumBehaviour = 'fast' | 'protected';
2
- interface RapidhashOptions {
3
- seed: bigint;
4
- rapidMumBehaviour: RapidMumBehaviour;
5
- }
6
-
7
- /**
8
- * Calculate a 64-bit hash value of the given message.
9
- *
10
- * @param message {string|Uint8Array|DataView} The message to be hashed.
11
- * @param options Options for modifying the hash calculation.
12
- * @param options.seed {bigint} 64-bit unsigned seed value.
13
- * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
14
- */
15
- declare function rapidhash_v1(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
16
- /**
17
- * Calculate a 64-bit hash value of the given message.
18
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
19
- *
20
- * @param message {string|Uint8Array|DataView} The message to be hashed.
21
- * @param options Options for modifying the hash calculation.
22
- * @param options.seed {bigint} 64-bit unsigned seed value.
23
- */
24
- declare function rapidhash_v1_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
25
- /**
26
- * Calculate a 64-bit hash value of the given message.
27
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
28
- *
29
- * @param message {string|Uint8Array|DataView} The message to be hashed.
30
- * @param options Options for modifying the hash calculation.
31
- * @param options.seed {bigint} 64-bit unsigned seed value.
32
- */
33
- declare function rapidhash_v1_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
34
-
35
- /**
36
- * Calculate a 64-bit hash value of the given message.
37
- *
38
- * @param message {string|Uint8Array|DataView} The message to be hashed.
39
- * @param options Options for modifying the hash calculation.
40
- * @param options.seed {bigint} 64-bit unsigned seed value.
41
- * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
42
- */
43
- declare function rapidhash_v2_0(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
44
- /**
45
- * Calculate a 64-bit hash value of the given message.
46
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
47
- *
48
- * @param message {string|Uint8Array|DataView} The message to be hashed.
49
- * @param options Options for modifying the hash calculation.
50
- * @param options.seed {bigint} 64-bit unsigned seed value.
51
- */
52
- declare function rapidhash_v2_0_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
53
- /**
54
- * Calculate a 64-bit hash value of the given message.
55
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
56
- *
57
- * @param message {string|Uint8Array|DataView} The message to be hashed.
58
- * @param options Options for modifying the hash calculation.
59
- * @param options.seed {bigint} 64-bit unsigned seed value.
60
- */
61
- declare function rapidhash_v2_0_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
62
-
63
- /**
64
- * Calculate a 64-bit hash value of the given message.
65
- *
66
- * @param message {string|Uint8Array|DataView} The message to be hashed.
67
- * @param options Options for modifying the hash calculation.
68
- * @param options.seed {bigint} 64-bit unsigned seed value.
69
- * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
70
- */
71
- declare function rapidhash_v2_2(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
72
- /**
73
- * Calculate a 64-bit hash value of the given message.
74
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
75
- *
76
- * @param message {string|Uint8Array|DataView} The message to be hashed.
77
- * @param options Options for modifying the hash calculation.
78
- * @param options.seed {bigint} 64-bit unsigned seed value.
79
- */
80
- declare function rapidhash_v2_2_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
81
- /**
82
- * Calculate a 64-bit hash value of the given message.
83
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
84
- *
85
- * @param message {string|Uint8Array|DataView} The message to be hashed.
86
- * @param options Options for modifying the hash calculation.
87
- * @param options.seed {bigint} 64-bit unsigned seed value.
88
- */
89
- declare function rapidhash_v2_2_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
90
-
91
- export { rapidhash_v2_2 as rapidhash, rapidhash_v2_2_fast as rapidhash_fast, rapidhash_v2_2_protected as rapidhash_protected, rapidhash_v1, rapidhash_v1_fast, rapidhash_v1_protected, rapidhash_v2_0, rapidhash_v2_0_fast, rapidhash_v2_0_protected, rapidhash_v2_2, rapidhash_v2_2_fast, rapidhash_v2_2_protected };
1
+ import { rapidhash, rapidhashMicro, rapidhashMicro_fast, rapidhashMicro_protected, rapidhashNano, rapidhashNano_fast, rapidhashNano_protected, rapidhash_fast, rapidhash_protected } from "./v3.0/index.mjs";
2
+ export { rapidhash, rapidhashMicro, rapidhashMicro_fast, rapidhashMicro_protected, rapidhashNano, rapidhashNano_fast, rapidhashNano_protected, rapidhash_fast, rapidhash_protected };
package/lib/index.d.ts CHANGED
@@ -1,91 +1,2 @@
1
- type RapidMumBehaviour = 'fast' | 'protected';
2
- interface RapidhashOptions {
3
- seed: bigint;
4
- rapidMumBehaviour: RapidMumBehaviour;
5
- }
6
-
7
- /**
8
- * Calculate a 64-bit hash value of the given message.
9
- *
10
- * @param message {string|Uint8Array|DataView} The message to be hashed.
11
- * @param options Options for modifying the hash calculation.
12
- * @param options.seed {bigint} 64-bit unsigned seed value.
13
- * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
14
- */
15
- declare function rapidhash_v1(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
16
- /**
17
- * Calculate a 64-bit hash value of the given message.
18
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
19
- *
20
- * @param message {string|Uint8Array|DataView} The message to be hashed.
21
- * @param options Options for modifying the hash calculation.
22
- * @param options.seed {bigint} 64-bit unsigned seed value.
23
- */
24
- declare function rapidhash_v1_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
25
- /**
26
- * Calculate a 64-bit hash value of the given message.
27
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
28
- *
29
- * @param message {string|Uint8Array|DataView} The message to be hashed.
30
- * @param options Options for modifying the hash calculation.
31
- * @param options.seed {bigint} 64-bit unsigned seed value.
32
- */
33
- declare function rapidhash_v1_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
34
-
35
- /**
36
- * Calculate a 64-bit hash value of the given message.
37
- *
38
- * @param message {string|Uint8Array|DataView} The message to be hashed.
39
- * @param options Options for modifying the hash calculation.
40
- * @param options.seed {bigint} 64-bit unsigned seed value.
41
- * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
42
- */
43
- declare function rapidhash_v2_0(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
44
- /**
45
- * Calculate a 64-bit hash value of the given message.
46
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
47
- *
48
- * @param message {string|Uint8Array|DataView} The message to be hashed.
49
- * @param options Options for modifying the hash calculation.
50
- * @param options.seed {bigint} 64-bit unsigned seed value.
51
- */
52
- declare function rapidhash_v2_0_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
53
- /**
54
- * Calculate a 64-bit hash value of the given message.
55
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
56
- *
57
- * @param message {string|Uint8Array|DataView} The message to be hashed.
58
- * @param options Options for modifying the hash calculation.
59
- * @param options.seed {bigint} 64-bit unsigned seed value.
60
- */
61
- declare function rapidhash_v2_0_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
62
-
63
- /**
64
- * Calculate a 64-bit hash value of the given message.
65
- *
66
- * @param message {string|Uint8Array|DataView} The message to be hashed.
67
- * @param options Options for modifying the hash calculation.
68
- * @param options.seed {bigint} 64-bit unsigned seed value.
69
- * @param options.rapidMumBehaviour {'fast'|'protected'} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
70
- */
71
- declare function rapidhash_v2_2(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
72
- /**
73
- * Calculate a 64-bit hash value of the given message.
74
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
75
- *
76
- * @param message {string|Uint8Array|DataView} The message to be hashed.
77
- * @param options Options for modifying the hash calculation.
78
- * @param options.seed {bigint} 64-bit unsigned seed value.
79
- */
80
- declare function rapidhash_v2_2_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
81
- /**
82
- * Calculate a 64-bit hash value of the given message.
83
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
84
- *
85
- * @param message {string|Uint8Array|DataView} The message to be hashed.
86
- * @param options Options for modifying the hash calculation.
87
- * @param options.seed {bigint} 64-bit unsigned seed value.
88
- */
89
- declare function rapidhash_v2_2_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
90
-
91
- export { rapidhash_v2_2 as rapidhash, rapidhash_v2_2_fast as rapidhash_fast, rapidhash_v2_2_protected as rapidhash_protected, rapidhash_v1, rapidhash_v1_fast, rapidhash_v1_protected, rapidhash_v2_0, rapidhash_v2_0_fast, rapidhash_v2_0_protected, rapidhash_v2_2, rapidhash_v2_2_fast, rapidhash_v2_2_protected };
1
+ import { rapidhash, rapidhashMicro, rapidhashMicro_fast, rapidhashMicro_protected, rapidhashNano, rapidhashNano_fast, rapidhashNano_protected, rapidhash_fast, rapidhash_protected } from "./v3.0/index.js";
2
+ export { rapidhash, rapidhashMicro, rapidhashMicro_fast, rapidhashMicro_protected, rapidhashNano, rapidhashNano_fast, rapidhashNano_protected, rapidhash_fast, rapidhash_protected };
package/lib/index.js CHANGED
@@ -1,467 +1,11 @@
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/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- rapidhash: () => rapidhash_v2_2,
24
- rapidhash_fast: () => rapidhash_v2_2_fast,
25
- rapidhash_protected: () => rapidhash_v2_2_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
35
- });
36
- module.exports = __toCommonJS(index_exports);
37
-
38
- // src/common.ts
39
- function rapid_mix_fast(a, b) {
40
- const m = a * b;
41
- return BigInt.asUintN(64, m) ^ m >> 64n;
42
- }
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
- function rapid_mix_protected(a, b) {
49
- const m = a * b;
50
- return BigInt.asUintN(64, m) ^ m >> 64n ^ a ^ b;
51
- }
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
- var read32x2Buffer = new Uint8Array(8);
60
- 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
- var read32Buffer = new Uint8Array(8);
67
- var read32View = new DataView(read32Buffer.buffer);
68
- function rapid_read32(buf, offset) {
69
- read32View.setUint32(0, buf.getUint32(offset, true), true);
70
- return read32View.getBigUint64(0, true);
71
- }
72
- function rapid_read64(buf, offset) {
73
- return buf.getBigUint64(offset, true);
74
- }
75
- var readSmallBuffer = new Uint8Array(8);
76
- 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
- var readBytesBuffer = new Uint8Array(8);
84
- 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
- var textEncoder = new TextEncoder();
91
- var utf8BufferSize = 2048;
92
- var stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
93
- var utf8Buffer = new Uint8Array(utf8BufferSize);
94
- function toDataView(message) {
95
- if (typeof message === "string") {
96
- if (message.length <= stringLengthThresholdToUseBuffer) {
97
- const { written } = textEncoder.encodeInto(message, utf8Buffer);
98
- return new DataView(utf8Buffer.buffer, 0, written);
99
- }
100
- const utf8bytes = textEncoder.encode(message);
101
- return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);
102
- }
103
- if (message instanceof Uint8Array) {
104
- return new DataView(message.buffer, message.byteOffset, message.byteLength);
105
- }
106
- return message;
107
- }
108
- 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
- function isBigUint64(value) {
120
- return value >= 0n && value <= 0xffffffffffffffffn;
121
- }
122
- function validateOptions(options, defaultSeed) {
123
- const result = {
124
- seed: defaultSeed,
125
- rapidMumBehaviour: defaultRapidMumBehaviour
126
- };
127
- if (options === void 0) {
128
- return result;
129
- }
130
- if (options.seed !== void 0) {
131
- if (!isBigUint64(options.seed)) {
132
- throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);
133
- }
134
- result.seed = options.seed;
135
- }
136
- if (options.rapidMumBehaviour !== void 0) {
137
- result.rapidMumBehaviour = options.rapidMumBehaviour;
138
- }
139
- return result;
140
- }
141
-
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
- // src/common_v2.ts
223
- var RAPID_SEED2 = 0n;
224
- var rapid_secret2 = [
225
- 0x2d358dccaa6c78a5n,
226
- 0x8bb84b93962eacc9n,
227
- 0x4b33a62ed433d4a3n,
228
- 0x4d5a2da51de1aa47n,
229
- 0xa0761d6478bd642fn,
230
- 0xe7037ed1a0b428dbn,
231
- 0x90ed1765281c388cn,
232
- 0xaaaaaaaaaaaaaaaan
233
- ];
234
-
235
- // src/rapidhash_v2.0.ts
236
- function rapidhash_v2_0_internal(key, seed, secret, rapid_mix, rapidhash_epilogue) {
237
- const len = key.byteLength;
238
- const lenBI = BigInt(key.byteLength);
239
- seed ^= rapid_mix(seed ^ secret[2], secret[1]) ^ lenBI;
240
- let a;
241
- let b;
242
- if (len <= 16) {
243
- if (len >= 4) {
244
- if (len >= 8) {
245
- const last = len - 8;
246
- a = rapid_read64(key, 0);
247
- b = rapid_read64(key, last);
248
- } else {
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);
332
- }
333
- function rapidhash_v2_0_protected(message, options) {
334
- const { seed } = validateOptions(options, RAPID_SEED2);
335
- return rapidhash_v2_0_internal(
336
- toDataView(message),
337
- seed,
338
- rapid_secret2,
339
- rapid_mix_protected,
340
- rapidhash_epilogue_protected
341
- );
342
- }
343
-
344
- // src/rapidhash_v2.2.ts
345
- function rapidhash_v2_2_internal(key, seed, secret, rapid_mix, rapidhash_epilogue) {
346
- const len = key.byteLength;
347
- const lenBI = BigInt(key.byteLength);
348
- seed ^= rapid_mix(seed ^ secret[2], secret[1]) ^ lenBI;
349
- let a;
350
- let b;
351
- if (len <= 16) {
352
- if (len >= 4) {
353
- if (len >= 8) {
354
- const last = len - 8;
355
- a = rapid_read64(key, 0);
356
- b = rapid_read64(key, last);
357
- } else {
358
- const last = len - 4;
359
- a = rapid_read32(key, 0);
360
- b = rapid_read32(key, last);
361
- }
362
- } else if (len > 0) {
363
- a = rapid_readBytes(key, 0, len - 1);
364
- b = BigInt(key.getUint8(len >> 1));
365
- } else {
366
- a = 0n;
367
- b = 0n;
368
- }
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
- } else {
380
- let i = len;
381
- let p = 0;
382
- let see1 = seed;
383
- let see2 = seed;
384
- let see3456;
385
- if (i >= 112) {
386
- let see3 = seed;
387
- let see4 = seed;
388
- let see5 = seed;
389
- let see6 = seed;
390
- do {
391
- seed = rapid_mix(rapid_read64(key, p) ^ secret[0], rapid_read64(key, p + 8) ^ seed);
392
- see1 = rapid_mix(rapid_read64(key, p + 16) ^ secret[1], rapid_read64(key, p + 24) ^ see1);
393
- see2 = rapid_mix(rapid_read64(key, p + 32) ^ secret[2], rapid_read64(key, p + 40) ^ see2);
394
- see3 = rapid_mix(rapid_read64(key, p + 48) ^ secret[3], rapid_read64(key, p + 56) ^ see3);
395
- see4 = rapid_mix(rapid_read64(key, p + 64) ^ secret[4], rapid_read64(key, p + 72) ^ see4);
396
- see5 = rapid_mix(rapid_read64(key, p + 80) ^ secret[5], rapid_read64(key, p + 88) ^ see5);
397
- see6 = rapid_mix(rapid_read64(key, p + 96) ^ secret[6], rapid_read64(key, p + 104) ^ see6);
398
- p += 112;
399
- i -= 112;
400
- } while (i >= 112);
401
- see3456 = see3 ^ see4 ^ see5 ^ see6;
402
- } else {
403
- see3456 = 0n;
404
- }
405
- if (i >= 48) {
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;
420
- if (i > 16) {
421
- seed = rapid_mix(rapid_read64(key, p) ^ secret[2], rapid_read64(key, p + 8) ^ seed);
422
- if (i > 32) {
423
- seed = rapid_mix(rapid_read64(key, p + 16) ^ secret[2], rapid_read64(key, p + 24) ^ seed);
424
- }
425
- }
426
- a = rapid_read64(key, p + i - 16);
427
- b = rapid_read64(key, p + i - 8);
428
- }
429
- a ^= secret[1];
430
- b ^= seed;
431
- return rapidhash_epilogue(a, b, secret[7], secret[1], lenBI);
432
- }
433
- function rapidhash_v2_2(message, options) {
434
- const { seed, rapidMumBehaviour } = validateOptions(options, RAPID_SEED2);
435
- const { rapid_mix, rapidhash_epilogue } = rapidMumImplementations[rapidMumBehaviour];
436
- return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret2, rapid_mix, rapidhash_epilogue);
437
- }
438
- function rapidhash_v2_2_fast(message, options) {
439
- const { seed } = validateOptions(options, RAPID_SEED2);
440
- return rapidhash_v2_2_internal(toDataView(message), seed, rapid_secret2, rapid_mix_fast, rapidhash_epilogue_fast);
441
- }
442
- function rapidhash_v2_2_protected(message, options) {
443
- const { seed } = validateOptions(options, RAPID_SEED2);
444
- return rapidhash_v2_2_internal(
445
- toDataView(message),
446
- seed,
447
- rapid_secret2,
448
- rapid_mix_protected,
449
- rapidhash_epilogue_protected
450
- );
451
- }
452
- // Annotate the CommonJS export names for ESM import in node:
453
- 0 && (module.exports = {
454
- rapidhash,
455
- 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
466
- });
467
- //# sourceMappingURL=index.js.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_v3_0 = require("./v3.0.js");
3
+ exports.rapidhash = require_v3_0.rapidhash;
4
+ exports.rapidhashMicro = require_v3_0.rapidhashMicro;
5
+ exports.rapidhashMicro_fast = require_v3_0.rapidhashMicro_fast;
6
+ exports.rapidhashMicro_protected = require_v3_0.rapidhashMicro_protected;
7
+ exports.rapidhashNano = require_v3_0.rapidhashNano;
8
+ exports.rapidhashNano_fast = require_v3_0.rapidhashNano_fast;
9
+ exports.rapidhashNano_protected = require_v3_0.rapidhashNano_protected;
10
+ exports.rapidhash_fast = require_v3_0.rapidhash_fast;
11
+ exports.rapidhash_protected = require_v3_0.rapidhash_protected;