rapidhash-js 3.0.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 (48) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/common.d.mts +7 -0
  3. package/lib/common.d.ts +7 -0
  4. package/lib/common.js +167 -0
  5. package/lib/common.js.map +1 -0
  6. package/lib/common.mjs +96 -0
  7. package/lib/common.mjs.map +1 -0
  8. package/lib/common_v2.js +26 -0
  9. package/lib/common_v2.js.map +1 -0
  10. package/lib/common_v2.mjs +15 -0
  11. package/lib/common_v2.mjs.map +1 -0
  12. package/lib/index.d.mts +2 -31
  13. package/lib/index.d.ts +2 -31
  14. package/lib/index.js +11 -248
  15. package/lib/index.mjs +1 -219
  16. package/lib/v1.0/index.d.mts +2 -3
  17. package/lib/v1.0/index.d.ts +2 -3
  18. package/lib/v1.0/index.js +96 -199
  19. package/lib/v1.0/index.js.map +1 -1
  20. package/lib/v1.0/index.mjs +93 -170
  21. package/lib/v1.0/index.mjs.map +1 -1
  22. package/lib/v2.0/index.d.mts +2 -3
  23. package/lib/v2.0/index.d.ts +2 -3
  24. package/lib/v2.0/index.js +118 -240
  25. package/lib/v2.0/index.js.map +1 -1
  26. package/lib/v2.0/index.mjs +115 -211
  27. package/lib/v2.0/index.mjs.map +1 -1
  28. package/lib/v2.2/index.d.mts +2 -3
  29. package/lib/v2.2/index.d.ts +2 -3
  30. package/lib/v2.2/index.js +118 -239
  31. package/lib/v2.2/index.js.map +1 -1
  32. package/lib/v2.2/index.mjs +115 -210
  33. package/lib/v2.2/index.mjs.map +1 -1
  34. package/lib/v3.0/index.d.mts +30 -6
  35. package/lib/v3.0/index.d.ts +30 -6
  36. package/lib/v3.0/index.js +11 -440
  37. package/lib/v3.0/index.mjs +1 -405
  38. package/lib/v3.0.js +407 -0
  39. package/lib/v3.0.js.map +1 -0
  40. package/lib/v3.0.mjs +354 -0
  41. package/lib/v3.0.mjs.map +1 -0
  42. package/package.json +5 -6
  43. package/lib/common-FK5Aq1u9.d.mts +0 -7
  44. package/lib/common-FK5Aq1u9.d.ts +0 -7
  45. package/lib/index.js.map +0 -1
  46. package/lib/index.mjs.map +0 -1
  47. package/lib/v3.0/index.js.map +0 -1
  48. package/lib/v3.0/index.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.0.1] - 2026-11-16
4
+
5
+ - Export `rapidhashMicro` and `rapidhashNano` (and their `_fast` / `_protected` functions) from the package root. The README documented importing them from `rapidhash-js`, but they were only available from `rapidhash-js/v3.0` ([#4](https://github.com/komiya-atsushi/rapidhash-js/issues/4)).
6
+
3
7
  ## [3.0.0] - 2025-11-24
4
8
 
5
9
  - Implement [rapidhash v3.0](https://github.com/Nicoshev/rapidhash).
@@ -0,0 +1,7 @@
1
+ type RapidMumBehaviour = 'fast' | 'protected';
2
+ interface RapidhashOptions {
3
+ seed: bigint;
4
+ rapidMumBehaviour: RapidMumBehaviour;
5
+ }
6
+ export { RapidhashOptions as t };
7
+ //# sourceMappingURL=common.d.mts.map
@@ -0,0 +1,7 @@
1
+ type RapidMumBehaviour = 'fast' | 'protected';
2
+ interface RapidhashOptions {
3
+ seed: bigint;
4
+ rapidMumBehaviour: RapidMumBehaviour;
5
+ }
6
+ export { RapidhashOptions as t };
7
+ //# sourceMappingURL=common.d.ts.map
package/lib/common.js ADDED
@@ -0,0 +1,167 @@
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
+ const read32x2View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
23
+ function rapid_read32x2(buf, offset1, offset2) {
24
+ read32x2View.setUint32(4, buf.getUint32(offset1, true), true);
25
+ read32x2View.setUint32(0, buf.getUint32(offset2, true), true);
26
+ return read32x2View.getBigUint64(0, true);
27
+ }
28
+ const read32View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
29
+ function rapid_read32(buf, offset) {
30
+ read32View.setUint32(0, buf.getUint32(offset, true), true);
31
+ return read32View.getBigUint64(0, true);
32
+ }
33
+ function rapid_read64(buf, offset) {
34
+ return buf.getBigUint64(offset, true);
35
+ }
36
+ const readSmallBuffer = /* @__PURE__ */ new Uint8Array(8);
37
+ const readSmallView = new DataView(readSmallBuffer.buffer);
38
+ function rapid_readSmall(buf, offset, k) {
39
+ readSmallBuffer[7] = buf.getUint8(offset);
40
+ readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));
41
+ readSmallBuffer[0] = buf.getUint8(offset + k - 1);
42
+ return readSmallView.getBigUint64(0, true);
43
+ }
44
+ const readBytesBuffer = /* @__PURE__ */ new Uint8Array(8);
45
+ const readBytesView = new DataView(readBytesBuffer.buffer);
46
+ function rapid_readBytes(buf, offset1, offset2) {
47
+ readBytesBuffer[0] = buf.getUint8(offset2);
48
+ readBytesBuffer[7] = buf.getUint8(offset1);
49
+ return readBytesView.getBigUint64(0, true);
50
+ }
51
+ const textEncoder = new TextEncoder();
52
+ const utf8BufferSize = 2048;
53
+ const stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
54
+ const utf8Buffer = new Uint8Array(utf8BufferSize);
55
+ function toDataView(message) {
56
+ if (typeof message === "string") {
57
+ if (message.length <= stringLengthThresholdToUseBuffer) {
58
+ const { written } = textEncoder.encodeInto(message, utf8Buffer);
59
+ return new DataView(utf8Buffer.buffer, 0, written);
60
+ }
61
+ const utf8bytes = textEncoder.encode(message);
62
+ return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);
63
+ }
64
+ if (message instanceof Uint8Array) return new DataView(message.buffer, message.byteOffset, message.byteLength);
65
+ return message;
66
+ }
67
+ const defaultRapidMumBehaviour = "fast";
68
+ const rapidMumImplementations = {
69
+ fast: {
70
+ rapid_mix: rapid_mix_fast,
71
+ rapidhash_epilogue: rapidhash_epilogue_fast
72
+ },
73
+ protected: {
74
+ rapid_mix: rapid_mix_protected,
75
+ rapidhash_epilogue: rapidhash_epilogue_protected
76
+ }
77
+ };
78
+ function isBigUint64(value) {
79
+ return value >= 0n && value <= 18446744073709551615n;
80
+ }
81
+ function validateOptions(options, defaultSeed) {
82
+ const result = {
83
+ seed: defaultSeed,
84
+ rapidMumBehaviour: defaultRapidMumBehaviour
85
+ };
86
+ if (options === void 0) return result;
87
+ if (options.seed !== void 0) {
88
+ if (!isBigUint64(options.seed)) throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);
89
+ result.seed = options.seed;
90
+ }
91
+ if (options.rapidMumBehaviour !== void 0) result.rapidMumBehaviour = options.rapidMumBehaviour;
92
+ return result;
93
+ }
94
+ Object.defineProperty(exports, "rapidMumImplementations", {
95
+ enumerable: true,
96
+ get: function() {
97
+ return rapidMumImplementations;
98
+ }
99
+ });
100
+ Object.defineProperty(exports, "rapid_mix_fast", {
101
+ enumerable: true,
102
+ get: function() {
103
+ return rapid_mix_fast;
104
+ }
105
+ });
106
+ Object.defineProperty(exports, "rapid_mix_protected", {
107
+ enumerable: true,
108
+ get: function() {
109
+ return rapid_mix_protected;
110
+ }
111
+ });
112
+ Object.defineProperty(exports, "rapid_read32", {
113
+ enumerable: true,
114
+ get: function() {
115
+ return rapid_read32;
116
+ }
117
+ });
118
+ Object.defineProperty(exports, "rapid_read32x2", {
119
+ enumerable: true,
120
+ get: function() {
121
+ return rapid_read32x2;
122
+ }
123
+ });
124
+ Object.defineProperty(exports, "rapid_read64", {
125
+ enumerable: true,
126
+ get: function() {
127
+ return rapid_read64;
128
+ }
129
+ });
130
+ Object.defineProperty(exports, "rapid_readBytes", {
131
+ enumerable: true,
132
+ get: function() {
133
+ return rapid_readBytes;
134
+ }
135
+ });
136
+ Object.defineProperty(exports, "rapid_readSmall", {
137
+ enumerable: true,
138
+ get: function() {
139
+ return rapid_readSmall;
140
+ }
141
+ });
142
+ Object.defineProperty(exports, "rapidhash_epilogue_fast", {
143
+ enumerable: true,
144
+ get: function() {
145
+ return rapidhash_epilogue_fast;
146
+ }
147
+ });
148
+ Object.defineProperty(exports, "rapidhash_epilogue_protected", {
149
+ enumerable: true,
150
+ get: function() {
151
+ return rapidhash_epilogue_protected;
152
+ }
153
+ });
154
+ Object.defineProperty(exports, "toDataView", {
155
+ enumerable: true,
156
+ get: function() {
157
+ return toDataView;
158
+ }
159
+ });
160
+ Object.defineProperty(exports, "validateOptions", {
161
+ enumerable: true,
162
+ get: function() {
163
+ return validateOptions;
164
+ }
165
+ });
166
+
167
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","names":[],"sources":["../src/common.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;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BAKT;CACF,MAAM;EACJ,WAAW;EACX,oBAAoB;CACtB;CACA,WAAW;EACT,WAAW;EACX,oBAAoB;CACtB;AACF;AAEA,SAAS,YAAY,OAAwB;CAC3C,OAAO,SAAS,MAAM,SAAS;AACjC;AAEA,SAAgB,gBAAgB,SAAgD,aAAuC;CACrH,MAAM,SAA2B;EAC/B,MAAM;EACN,mBAAmB;CACrB;CAEA,IAAI,YAAY,KAAA,GACd,OAAO;CAGT,IAAI,QAAQ,SAAS,KAAA,GAAW;EAC9B,IAAI,CAAC,YAAY,QAAQ,IAAI,GAC3B,MAAM,IAAI,MAAM,gDAAgD,QAAQ,MAAM;EAEhF,OAAO,OAAO,QAAQ;CACxB;CAEA,IAAI,QAAQ,sBAAsB,KAAA,GAChC,OAAO,oBAAoB,QAAQ;CAGrC,OAAO;AACT"}
package/lib/common.mjs ADDED
@@ -0,0 +1,96 @@
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
+ const read32x2View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
23
+ function rapid_read32x2(buf, offset1, offset2) {
24
+ read32x2View.setUint32(4, buf.getUint32(offset1, true), true);
25
+ read32x2View.setUint32(0, buf.getUint32(offset2, true), true);
26
+ return read32x2View.getBigUint64(0, true);
27
+ }
28
+ const read32View = new DataView((/* @__PURE__ */ new Uint8Array(8)).buffer);
29
+ function rapid_read32(buf, offset) {
30
+ read32View.setUint32(0, buf.getUint32(offset, true), true);
31
+ return read32View.getBigUint64(0, true);
32
+ }
33
+ function rapid_read64(buf, offset) {
34
+ return buf.getBigUint64(offset, true);
35
+ }
36
+ const readSmallBuffer = /* @__PURE__ */ new Uint8Array(8);
37
+ const readSmallView = new DataView(readSmallBuffer.buffer);
38
+ function rapid_readSmall(buf, offset, k) {
39
+ readSmallBuffer[7] = buf.getUint8(offset);
40
+ readSmallBuffer[4] = buf.getUint8(offset + (k >> 1));
41
+ readSmallBuffer[0] = buf.getUint8(offset + k - 1);
42
+ return readSmallView.getBigUint64(0, true);
43
+ }
44
+ const readBytesBuffer = /* @__PURE__ */ new Uint8Array(8);
45
+ const readBytesView = new DataView(readBytesBuffer.buffer);
46
+ function rapid_readBytes(buf, offset1, offset2) {
47
+ readBytesBuffer[0] = buf.getUint8(offset2);
48
+ readBytesBuffer[7] = buf.getUint8(offset1);
49
+ return readBytesView.getBigUint64(0, true);
50
+ }
51
+ const textEncoder = new TextEncoder();
52
+ const utf8BufferSize = 2048;
53
+ const stringLengthThresholdToUseBuffer = utf8BufferSize / 3;
54
+ const utf8Buffer = new Uint8Array(utf8BufferSize);
55
+ function toDataView(message) {
56
+ if (typeof message === "string") {
57
+ if (message.length <= stringLengthThresholdToUseBuffer) {
58
+ const { written } = textEncoder.encodeInto(message, utf8Buffer);
59
+ return new DataView(utf8Buffer.buffer, 0, written);
60
+ }
61
+ const utf8bytes = textEncoder.encode(message);
62
+ return new DataView(utf8bytes.buffer, utf8bytes.byteOffset, utf8bytes.byteLength);
63
+ }
64
+ if (message instanceof Uint8Array) return new DataView(message.buffer, message.byteOffset, message.byteLength);
65
+ return message;
66
+ }
67
+ const defaultRapidMumBehaviour = "fast";
68
+ const rapidMumImplementations = {
69
+ fast: {
70
+ rapid_mix: rapid_mix_fast,
71
+ rapidhash_epilogue: rapidhash_epilogue_fast
72
+ },
73
+ protected: {
74
+ rapid_mix: rapid_mix_protected,
75
+ rapidhash_epilogue: rapidhash_epilogue_protected
76
+ }
77
+ };
78
+ function isBigUint64(value) {
79
+ return value >= 0n && value <= 18446744073709551615n;
80
+ }
81
+ function validateOptions(options, defaultSeed) {
82
+ const result = {
83
+ seed: defaultSeed,
84
+ rapidMumBehaviour: defaultRapidMumBehaviour
85
+ };
86
+ if (options === void 0) return result;
87
+ if (options.seed !== void 0) {
88
+ if (!isBigUint64(options.seed)) throw new Error(`seed must be a 64-bit unsigned bigint value: ${options.seed}`);
89
+ result.seed = options.seed;
90
+ }
91
+ if (options.rapidMumBehaviour !== void 0) result.rapidMumBehaviour = options.rapidMumBehaviour;
92
+ return result;
93
+ }
94
+ export { rapid_read32x2 as a, rapid_readSmall as c, toDataView as d, validateOptions as f, rapid_read32 as i, rapidhash_epilogue_fast as l, rapid_mix_fast as n, rapid_read64 as o, rapid_mix_protected as r, rapid_readBytes as s, rapidMumImplementations as t, rapidhash_epilogue_protected as u };
95
+
96
+ //# sourceMappingURL=common.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.mjs","names":[],"sources":["../src/common.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.rapidMumBehavi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AAW;EACX,oBAAoB;CACtB;AACF;AAEA,SAAS,YAAY,OAAwB;CAC3C,OAAO,SAAS,MAAM,SAAS;AACjC;AAEA,SAAgB,gBAAgB,SAAgD,aAAuC;CACrH,MAAM,SAA2B;EAC/B,MAAM;EACN,mBAAmB;CACrB;CAEA,IAAI,YAAY,KAAA,GACd,OAAO;CAGT,IAAI,QAAQ,SAAS,KAAA,GAAW;EAC9B,IAAI,CAAC,YAAY,QAAQ,IAAI,GAC3B,MAAM,IAAI,MAAM,gDAAgD,QAAQ,MAAM;EAEhF,OAAO,OAAO,QAAQ;CACxB;CAEA,IAAI,QAAQ,sBAAsB,KAAA,GAChC,OAAO,oBAAoB,QAAQ;CAGrC,OAAO;AACT"}
@@ -0,0 +1,26 @@
1
+ // src/common_v2.ts
2
+ const RAPID_SEED = 0n;
3
+ const rapid_secret = [
4
+ 3257665815644502181n,
5
+ 10067880064238660809n,
6
+ 5418857496715711651n,
7
+ 5573817676018592327n,
8
+ 11562461410679940143n,
9
+ 16646288086500911323n,
10
+ 10443028834174122124n,
11
+ 12297829382473034410n
12
+ ];
13
+ Object.defineProperty(exports, "RAPID_SEED", {
14
+ enumerable: true,
15
+ get: function() {
16
+ return RAPID_SEED;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "rapid_secret", {
20
+ enumerable: true,
21
+ get: function() {
22
+ return rapid_secret;
23
+ }
24
+ });
25
+
26
+ //# sourceMappingURL=common_v2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common_v2.js","names":[],"sources":["../src/common_v2.ts"],"sourcesContent":["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"],"mappings":";AAEA,MAAa,aAAa;AAC1B,MAAa,eAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -0,0 +1,15 @@
1
+ // src/common_v2.ts
2
+ const RAPID_SEED = 0n;
3
+ const rapid_secret = [
4
+ 3257665815644502181n,
5
+ 10067880064238660809n,
6
+ 5418857496715711651n,
7
+ 5573817676018592327n,
8
+ 11562461410679940143n,
9
+ 16646288086500911323n,
10
+ 10443028834174122124n,
11
+ 12297829382473034410n
12
+ ];
13
+ export { rapid_secret as n, RAPID_SEED as t };
14
+
15
+ //# sourceMappingURL=common_v2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common_v2.mjs","names":[],"sources":["../src/common_v2.ts"],"sourcesContent":["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"],"mappings":";AAEA,MAAa,aAAa;AAC1B,MAAa,eAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
package/lib/index.d.mts CHANGED
@@ -1,31 +1,2 @@
1
- import { R as RapidhashOptions } from './common-FK5Aq1u9.mjs';
2
-
3
- /**
4
- * Calculate a 64-bit hash value of the given message.
5
- *
6
- * @param message {string|Uint8Array|DataView} The message to be hashed.
7
- * @param options Options for modifying the hash calculation.
8
- * @param options.seed {bigint} 64-bit unsigned seed value.
9
- * @param options.rapidMumBehaviour {"fast"|"protected"} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
10
- */
11
- declare function rapidhash(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
12
- /**
13
- * Calculate a 64-bit hash value of the given message.
14
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
15
- *
16
- * @param message {string|Uint8Array|DataView} The message to be hashed.
17
- * @param options Options for modifying the hash calculation.
18
- * @param options.seed {bigint} 64-bit unsigned seed value.
19
- */
20
- declare function rapidhash_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
21
- /**
22
- * Calculate a 64-bit hash value of the given message.
23
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
24
- *
25
- * @param message {string|Uint8Array|DataView} The message to be hashed.
26
- * @param options Options for modifying the hash calculation.
27
- * @param options.seed {bigint} 64-bit unsigned seed value.
28
- */
29
- declare function rapidhash_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
30
-
31
- export { rapidhash, rapidhash_fast, rapidhash_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,31 +1,2 @@
1
- import { R as RapidhashOptions } from './common-FK5Aq1u9.js';
2
-
3
- /**
4
- * Calculate a 64-bit hash value of the given message.
5
- *
6
- * @param message {string|Uint8Array|DataView} The message to be hashed.
7
- * @param options Options for modifying the hash calculation.
8
- * @param options.seed {bigint} 64-bit unsigned seed value.
9
- * @param options.rapidMumBehaviour {"fast"|"protected"} Alters behaviour of the rapid_mum function. Defaults to 'fast'.
10
- */
11
- declare function rapidhash(message: string | Uint8Array | DataView, options?: Partial<RapidhashOptions>): bigint;
12
- /**
13
- * Calculate a 64-bit hash value of the given message.
14
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'fast'.
15
- *
16
- * @param message {string|Uint8Array|DataView} The message to be hashed.
17
- * @param options Options for modifying the hash calculation.
18
- * @param options.seed {bigint} 64-bit unsigned seed value.
19
- */
20
- declare function rapidhash_fast(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
21
- /**
22
- * Calculate a 64-bit hash value of the given message.
23
- * This function is equivalent to rapidhash() with options.rapidMumBehaviour set to 'protected'.
24
- *
25
- * @param message {string|Uint8Array|DataView} The message to be hashed.
26
- * @param options Options for modifying the hash calculation.
27
- * @param options.seed {bigint} 64-bit unsigned seed value.
28
- */
29
- declare function rapidhash_protected(message: string | Uint8Array | DataView, options?: Partial<Omit<RapidhashOptions, 'rapidMumBehaviour'>>): bigint;
30
-
31
- export { rapidhash, rapidhash_fast, rapidhash_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 };