distillate 0.9.0 → 0.11.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.
Files changed (42) hide show
  1. package/README.md +44 -6
  2. package/dist/bitset-Cf2jwRJX.js +32 -0
  3. package/dist/bitset-QYGqxnEf.cjs +37 -0
  4. package/dist/blocked/index.cjs +14 -9
  5. package/dist/blocked/index.d.cts +7 -6
  6. package/dist/blocked/index.d.ts +7 -6
  7. package/dist/blocked/index.js +12 -8
  8. package/dist/bloom/index.cjs +16 -41
  9. package/dist/bloom/index.d.cts +5 -4
  10. package/dist/bloom/index.d.ts +5 -4
  11. package/dist/bloom/index.js +13 -39
  12. package/dist/bytes-DCuYtUVS.d.cts +4 -0
  13. package/dist/bytes-DCuYtUVS.d.ts +4 -0
  14. package/dist/frame/index.cjs +9 -0
  15. package/dist/frame/index.d.cts +2 -0
  16. package/dist/frame/index.d.ts +2 -0
  17. package/dist/frame/index.js +2 -0
  18. package/dist/fuse/index.cjs +26 -22
  19. package/dist/fuse/index.d.cts +7 -6
  20. package/dist/fuse/index.d.ts +7 -6
  21. package/dist/fuse/index.js +14 -11
  22. package/dist/hasher-3Cyn7Yg-.js +230 -0
  23. package/dist/hasher-MhY7aQ8F.cjs +289 -0
  24. package/dist/hll/index.cjs +12 -8
  25. package/dist/hll/index.d.cts +4 -3
  26. package/dist/hll/index.d.ts +4 -3
  27. package/dist/hll/index.js +11 -8
  28. package/dist/index.cjs +1 -1
  29. package/dist/index.d.cts +2 -3
  30. package/dist/index.d.ts +2 -3
  31. package/dist/index.js +1 -1
  32. package/dist/scalable/index.cjs +340 -0
  33. package/dist/scalable/index.d.cts +173 -0
  34. package/dist/scalable/index.d.ts +173 -0
  35. package/dist/scalable/index.js +330 -0
  36. package/dist/{serialize-Bv1zWzrh.d.cts → serialize--xR6vGSW.d.cts} +44 -8
  37. package/dist/{serialize-Bv1zWzrh.d.ts → serialize--xR6vGSW.d.ts} +44 -8
  38. package/dist/serialize-CHikZ4GH.cjs +296 -0
  39. package/dist/serialize-CMSYFym-.js +201 -0
  40. package/package.json +25 -9
  41. package/dist/serialize-D59Ri81a.js +0 -392
  42. package/dist/serialize-Ul2LKFJU.cjs +0 -517
@@ -0,0 +1,2 @@
1
+ import { a as TruncatedError, i as SerializationError, n as ChecksumError, p as readFrameAt, r as ReservedBitsError, s as UnknownVersionError, t as BadMagicError } from "../serialize-CMSYFym-.js";
2
+ export { BadMagicError, ChecksumError, ReservedBitsError, SerializationError, TruncatedError, UnknownVersionError, readFrameAt };
@@ -1,9 +1,11 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_serialize = require("../serialize-Ul2LKFJU.cjs");
2
+ const require_hasher = require("../hasher-MhY7aQ8F.cjs");
3
+ const require_serialize = require("../serialize-CHikZ4GH.cjs");
3
4
  //#region src/fuse/fuse.ts
4
5
  const ARITY = 3;
5
6
  const TYPE_FUSE8 = 3;
6
7
  const TYPE_FUSE16 = 4;
8
+ const PARAMS_SIZE = 16;
7
9
  var BinaryFuseBuildError = class extends Error {
8
10
  name = "BinaryFuseBuildError";
9
11
  };
@@ -16,14 +18,14 @@ const scratchHash = {
16
18
  function mixSeed(lo, hi, seed) {
17
19
  const l = (lo >>> 0) + (seed >>> 0);
18
20
  const carry = l > 4294967295 ? 1 : 0;
19
- require_serialize.fmix64(l >>> 0, hi + carry >>> 0);
21
+ require_hasher.fmix64(l >>> 0, hi + carry >>> 0);
20
22
  }
21
23
  function mulhi64(lo, hi, n) {
22
- require_serialize.mul64(hi, 0, n, 0);
23
- const aLo = require_serialize.RLO;
24
- const aHi = require_serialize.RHI;
25
- require_serialize.mul64(lo, 0, n, 0);
26
- const bHi = require_serialize.RHI;
24
+ require_hasher.mul64(hi, 0, n, 0);
25
+ const aLo = require_hasher.RLO;
26
+ const aHi = require_hasher.RHI;
27
+ require_hasher.mul64(lo, 0, n, 0);
28
+ const bHi = require_hasher.RHI;
27
29
  return aHi + ((aLo >>> 0) + (bHi >>> 0) > 4294967295 ? 1 : 0) >>> 0;
28
30
  }
29
31
  function positionsInto(mlo, mhi, seg, segMask, segCountLen, out) {
@@ -44,10 +46,10 @@ function computeParams(size) {
44
46
  const segMask = seg - 1;
45
47
  const sizeFactor = Math.max(1.125, .875 + .25 * Math.log(1e6) / Math.log(Math.max(size, 2)));
46
48
  const capacity = Math.round(size * sizeFactor);
47
- let segCount = Math.floor((capacity + seg - 1) / seg) - (ARITY - 1);
49
+ let segCount = Math.floor((capacity + seg - 1) / seg) - 2;
48
50
  if (segCount <= 0) segCount = 1;
49
51
  let arrayLength = (segCount + ARITY - 1) * seg;
50
- segCount = Math.floor((arrayLength + seg - 1) / seg) - (ARITY - 1);
52
+ segCount = Math.floor((arrayLength + seg - 1) / seg) - 2;
51
53
  if (segCount <= 0) segCount = 1;
52
54
  arrayLength = (segCount + ARITY - 1) * seg;
53
55
  return {
@@ -79,8 +81,8 @@ function buildFingerprints(fp, hashes, params, maxAttempts = 100) {
79
81
  xorHi.fill(0);
80
82
  for (let i = 0; i < size; i++) {
81
83
  mixSeed(hashes[2 * i] ?? 0, hashes[2 * i + 1] ?? 0, seed);
82
- const mlo = require_serialize.RLO;
83
- const mhi = require_serialize.RHI;
84
+ const mlo = require_hasher.RLO;
85
+ const mhi = require_hasher.RHI;
84
86
  positionsInto(mlo, mhi, seg, segMask, segCountLen, pos);
85
87
  for (let j = 0; j < 3; j++) {
86
88
  const p = pos[j] ?? 0;
@@ -132,7 +134,7 @@ function buildState(keys, alloc) {
132
134
  const hashList = [];
133
135
  const seen = new Set();
134
136
  for (const key of keys) {
135
- require_serialize.hash128KeyInto(key, 0, scratchHash);
137
+ require_hasher.hash128KeyInto(key, 0, scratchHash);
136
138
  const lo = scratchHash.w0 >>> 0;
137
139
  const hi = scratchHash.w1 >>> 0;
138
140
  const id = `${String(lo)},${String(hi)}`;
@@ -161,7 +163,7 @@ function fuseStateFromBytes(bytes, expectedType) {
161
163
  const { type, flags, body } = require_serialize.readHeader(bytes);
162
164
  if (type !== expectedType) throw new require_serialize.SerializationError(`expected DSTL type ${String(expectedType)}, got ${String(type)}`);
163
165
  if ((flags & 15) !== 0) throw new require_serialize.UnknownHashVariantError(`unsupported hash variant ${String(flags & 15)}`);
164
- require_serialize.assertMinBodyLength(body.length, 16, "fuse");
166
+ require_serialize.assertMinBodyLength(body.length, PARAMS_SIZE, "fuse");
165
167
  const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
166
168
  const seed = dv.getUint32(0, true);
167
169
  const seg = dv.getUint32(4, true);
@@ -171,8 +173,8 @@ function fuseStateFromBytes(bytes, expectedType) {
171
173
  if (segCountLen % seg !== 0) throw new require_serialize.SerializationError(`fuse segment count length ${String(segCountLen)} is not a multiple of segment length ${String(seg)}`);
172
174
  const bpe = expectedType === TYPE_FUSE8 ? 1 : 2;
173
175
  const expectedArrayLength = size === 0 ? 0 : segCountLen + 2 * seg;
174
- require_serialize.assertBodyLength(body.length, 16 + expectedArrayLength * bpe, "fuse");
175
- const laneBytes = body.subarray(16);
176
+ require_serialize.assertBodyLength(body.length, PARAMS_SIZE + expectedArrayLength * bpe, "fuse");
177
+ const laneBytes = body.subarray(PARAMS_SIZE);
176
178
  const arrayLength = laneBytes.length / bpe;
177
179
  const fp = bpe === 1 ? new Uint8Array(arrayLength) : new Uint16Array(arrayLength);
178
180
  new Uint8Array(fp.buffer).set(laneBytes);
@@ -215,24 +217,25 @@ var BinaryFuse = class {
215
217
  }
216
218
  toBytes() {
217
219
  const laneBytes = new Uint8Array(this.#fp.buffer, this.#fp.byteOffset, this.#fp.byteLength);
220
+ const type = this.#fp.BYTES_PER_ELEMENT === 1 ? TYPE_FUSE8 : TYPE_FUSE16;
218
221
  return require_serialize.writeFrame({
219
- version: 4,
220
- type: this.#fp.BYTES_PER_ELEMENT === 1 ? TYPE_FUSE8 : TYPE_FUSE16,
222
+ version: 5,
223
+ type,
221
224
  flags: 0
222
- }, 16 + laneBytes.length, (body, dv) => {
225
+ }, PARAMS_SIZE, laneBytes.length, (body, dv) => {
223
226
  dv.setUint32(0, this.#seed, true);
224
227
  dv.setUint32(4, this.#seg, true);
225
228
  dv.setUint32(8, this.#segCountLen, true);
226
229
  dv.setUint32(12, this.#size, true);
227
- body.set(laneBytes, 16);
230
+ body.set(laneBytes, PARAMS_SIZE);
228
231
  });
229
232
  }
230
233
  has(key) {
231
234
  if (this.#fp.length === 0) return false;
232
- require_serialize.hash128KeyInto(key, 0, scratchHash);
235
+ require_hasher.hash128KeyInto(key, 0, scratchHash);
233
236
  mixSeed(scratchHash.w0 >>> 0, scratchHash.w1 >>> 0, this.#seed);
234
- const mlo = require_serialize.RLO;
235
- const mhi = require_serialize.RHI;
237
+ const mlo = require_hasher.RLO;
238
+ const mhi = require_hasher.RHI;
236
239
  positionsInto(mlo, mhi, this.#seg, this.#segMask, this.#segCountLen, this.#pos);
237
240
  const mask = fpMask(this.#fp);
238
241
  const p0 = this.#pos[0] ?? 0;
@@ -275,6 +278,7 @@ exports.BinaryFuse16 = BinaryFuse16;
275
278
  exports.BinaryFuse8 = BinaryFuse8;
276
279
  exports.BinaryFuseBuildError = BinaryFuseBuildError;
277
280
  exports.ChecksumError = require_serialize.ChecksumError;
281
+ exports.ReservedBitsError = require_serialize.ReservedBitsError;
278
282
  exports.SerializationError = require_serialize.SerializationError;
279
283
  exports.TruncatedError = require_serialize.TruncatedError;
280
284
  exports.UnknownHashVariantError = require_serialize.UnknownHashVariantError;
@@ -1,7 +1,8 @@
1
- import { a as TruncatedError, c as BytesLike, i as SerializationError, n as ChecksumError, o as UnknownHashVariantError, r as FilterJSON, s as UnknownVersionError, t as BadMagicError } from "../serialize-Bv1zWzrh.cjs";
1
+ import { t as BytesLike } from "../bytes-DCuYtUVS.cjs";
2
+ import { a as ReservedBitsError, c as UnknownHashVariantError, l as UnknownVersionError, n as ChecksumError, o as SerializationError, r as FilterJSON, s as TruncatedError, t as BadMagicError } from "../serialize--xR6vGSW.cjs";
2
3
  //#region src/fuse/fuse.d.ts
3
4
  /** Thrown when binary fuse construction fails to converge on the key set. */
4
- declare class BinaryFuseBuildError extends Error {
5
+ export declare class BinaryFuseBuildError extends Error {
5
6
  /** Discriminates this error from other `Error`s. */
6
7
  override readonly name = "BinaryFuseBuildError";
7
8
  }
@@ -20,7 +21,7 @@ interface FuseParams {
20
21
  * @param width - Fingerprint width in bits: `8` for {@link BinaryFuse8}, `16` for {@link BinaryFuse16}.
21
22
  * @returns Bits per key (`0` for an empty filter).
22
23
  */
23
- declare function fuseBitsPerKey(n: number, width: 8 | 16): number;
24
+ export declare function fuseBitsPerKey(n: number, width: 8 | 16): number;
24
25
  interface FuseState {
25
26
  fp: Uint8Array | Uint16Array;
26
27
  seed: number;
@@ -81,7 +82,7 @@ declare abstract class BinaryFuse {
81
82
  * filter.size; // 3
82
83
  * ```
83
84
  */
84
- declare class BinaryFuse8 extends BinaryFuse {
85
+ export declare class BinaryFuse8 extends BinaryFuse {
85
86
  /**
86
87
  * Builds a filter from the given keys; duplicates are ignored.
87
88
  *
@@ -115,7 +116,7 @@ declare class BinaryFuse8 extends BinaryFuse {
115
116
  * filter.has("alice"); // true
116
117
  * ```
117
118
  */
118
- declare class BinaryFuse16 extends BinaryFuse {
119
+ export declare class BinaryFuse16 extends BinaryFuse {
119
120
  /**
120
121
  * Builds a filter from the given keys; duplicates are ignored.
121
122
  *
@@ -140,4 +141,4 @@ declare class BinaryFuse16 extends BinaryFuse {
140
141
  static fromJSON(value: unknown): BinaryFuse16;
141
142
  }
142
143
  //#endregion
143
- export { BadMagicError, BinaryFuse16, BinaryFuse8, BinaryFuseBuildError, ChecksumError, type FilterJSON, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, fuseBitsPerKey };
144
+ export { BadMagicError, ChecksumError, type FilterJSON, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError };
@@ -1,7 +1,8 @@
1
- import { a as TruncatedError, c as BytesLike, i as SerializationError, n as ChecksumError, o as UnknownHashVariantError, r as FilterJSON, s as UnknownVersionError, t as BadMagicError } from "../serialize-Bv1zWzrh.js";
1
+ import { t as BytesLike } from "../bytes-DCuYtUVS.js";
2
+ import { a as ReservedBitsError, c as UnknownHashVariantError, l as UnknownVersionError, n as ChecksumError, o as SerializationError, r as FilterJSON, s as TruncatedError, t as BadMagicError } from "../serialize--xR6vGSW.js";
2
3
  //#region src/fuse/fuse.d.ts
3
4
  /** Thrown when binary fuse construction fails to converge on the key set. */
4
- declare class BinaryFuseBuildError extends Error {
5
+ export declare class BinaryFuseBuildError extends Error {
5
6
  /** Discriminates this error from other `Error`s. */
6
7
  override readonly name = "BinaryFuseBuildError";
7
8
  }
@@ -20,7 +21,7 @@ interface FuseParams {
20
21
  * @param width - Fingerprint width in bits: `8` for {@link BinaryFuse8}, `16` for {@link BinaryFuse16}.
21
22
  * @returns Bits per key (`0` for an empty filter).
22
23
  */
23
- declare function fuseBitsPerKey(n: number, width: 8 | 16): number;
24
+ export declare function fuseBitsPerKey(n: number, width: 8 | 16): number;
24
25
  interface FuseState {
25
26
  fp: Uint8Array | Uint16Array;
26
27
  seed: number;
@@ -81,7 +82,7 @@ declare abstract class BinaryFuse {
81
82
  * filter.size; // 3
82
83
  * ```
83
84
  */
84
- declare class BinaryFuse8 extends BinaryFuse {
85
+ export declare class BinaryFuse8 extends BinaryFuse {
85
86
  /**
86
87
  * Builds a filter from the given keys; duplicates are ignored.
87
88
  *
@@ -115,7 +116,7 @@ declare class BinaryFuse8 extends BinaryFuse {
115
116
  * filter.has("alice"); // true
116
117
  * ```
117
118
  */
118
- declare class BinaryFuse16 extends BinaryFuse {
119
+ export declare class BinaryFuse16 extends BinaryFuse {
119
120
  /**
120
121
  * Builds a filter from the given keys; duplicates are ignored.
121
122
  *
@@ -140,4 +141,4 @@ declare class BinaryFuse16 extends BinaryFuse {
140
141
  static fromJSON(value: unknown): BinaryFuse16;
141
142
  }
142
143
  //#endregion
143
- export { BadMagicError, BinaryFuse16, BinaryFuse8, BinaryFuseBuildError, ChecksumError, type FilterJSON, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, fuseBitsPerKey };
144
+ export { BadMagicError, ChecksumError, type FilterJSON, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError };
@@ -1,8 +1,10 @@
1
- import { _ as hash128KeyInto, a as UnknownHashVariantError, c as assertMinBodyLength, d as readHeader, f as toJSONEnvelope, g as fmix64, h as RLO, i as TruncatedError, l as bytesEqual, m as RHI, n as ChecksumError, o as UnknownVersionError, p as writeFrame, r as SerializationError, s as assertBodyLength, t as BadMagicError, u as fromJSONEnvelope, y as mul64 } from "../serialize-D59Ri81a.js";
1
+ import { i as hash128KeyInto, n as RLO, o as mul64, r as fmix64, t as RHI } from "../hasher-3Cyn7Yg-.js";
2
+ import { a as TruncatedError, c as assertBodyLength, d as bytesEqual, f as fromJSONEnvelope, g as writeFrame, h as toJSONEnvelope, i as SerializationError, l as assertMinBodyLength, m as readHeader, n as ChecksumError, o as UnknownHashVariantError, r as ReservedBitsError, s as UnknownVersionError, t as BadMagicError } from "../serialize-CMSYFym-.js";
2
3
  //#region src/fuse/fuse.ts
3
4
  const ARITY = 3;
4
5
  const TYPE_FUSE8 = 3;
5
6
  const TYPE_FUSE16 = 4;
7
+ const PARAMS_SIZE = 16;
6
8
  var BinaryFuseBuildError = class extends Error {
7
9
  name = "BinaryFuseBuildError";
8
10
  };
@@ -43,10 +45,10 @@ function computeParams(size) {
43
45
  const segMask = seg - 1;
44
46
  const sizeFactor = Math.max(1.125, .875 + .25 * Math.log(1e6) / Math.log(Math.max(size, 2)));
45
47
  const capacity = Math.round(size * sizeFactor);
46
- let segCount = Math.floor((capacity + seg - 1) / seg) - (ARITY - 1);
48
+ let segCount = Math.floor((capacity + seg - 1) / seg) - 2;
47
49
  if (segCount <= 0) segCount = 1;
48
50
  let arrayLength = (segCount + ARITY - 1) * seg;
49
- segCount = Math.floor((arrayLength + seg - 1) / seg) - (ARITY - 1);
51
+ segCount = Math.floor((arrayLength + seg - 1) / seg) - 2;
50
52
  if (segCount <= 0) segCount = 1;
51
53
  arrayLength = (segCount + ARITY - 1) * seg;
52
54
  return {
@@ -160,7 +162,7 @@ function fuseStateFromBytes(bytes, expectedType) {
160
162
  const { type, flags, body } = readHeader(bytes);
161
163
  if (type !== expectedType) throw new SerializationError(`expected DSTL type ${String(expectedType)}, got ${String(type)}`);
162
164
  if ((flags & 15) !== 0) throw new UnknownHashVariantError(`unsupported hash variant ${String(flags & 15)}`);
163
- assertMinBodyLength(body.length, 16, "fuse");
165
+ assertMinBodyLength(body.length, PARAMS_SIZE, "fuse");
164
166
  const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
165
167
  const seed = dv.getUint32(0, true);
166
168
  const seg = dv.getUint32(4, true);
@@ -170,8 +172,8 @@ function fuseStateFromBytes(bytes, expectedType) {
170
172
  if (segCountLen % seg !== 0) throw new SerializationError(`fuse segment count length ${String(segCountLen)} is not a multiple of segment length ${String(seg)}`);
171
173
  const bpe = expectedType === TYPE_FUSE8 ? 1 : 2;
172
174
  const expectedArrayLength = size === 0 ? 0 : segCountLen + 2 * seg;
173
- assertBodyLength(body.length, 16 + expectedArrayLength * bpe, "fuse");
174
- const laneBytes = body.subarray(16);
175
+ assertBodyLength(body.length, PARAMS_SIZE + expectedArrayLength * bpe, "fuse");
176
+ const laneBytes = body.subarray(PARAMS_SIZE);
175
177
  const arrayLength = laneBytes.length / bpe;
176
178
  const fp = bpe === 1 ? new Uint8Array(arrayLength) : new Uint16Array(arrayLength);
177
179
  new Uint8Array(fp.buffer).set(laneBytes);
@@ -214,16 +216,17 @@ var BinaryFuse = class {
214
216
  }
215
217
  toBytes() {
216
218
  const laneBytes = new Uint8Array(this.#fp.buffer, this.#fp.byteOffset, this.#fp.byteLength);
219
+ const type = this.#fp.BYTES_PER_ELEMENT === 1 ? TYPE_FUSE8 : TYPE_FUSE16;
217
220
  return writeFrame({
218
- version: 4,
219
- type: this.#fp.BYTES_PER_ELEMENT === 1 ? TYPE_FUSE8 : TYPE_FUSE16,
221
+ version: 5,
222
+ type,
220
223
  flags: 0
221
- }, 16 + laneBytes.length, (body, dv) => {
224
+ }, PARAMS_SIZE, laneBytes.length, (body, dv) => {
222
225
  dv.setUint32(0, this.#seed, true);
223
226
  dv.setUint32(4, this.#seg, true);
224
227
  dv.setUint32(8, this.#segCountLen, true);
225
228
  dv.setUint32(12, this.#size, true);
226
- body.set(laneBytes, 16);
229
+ body.set(laneBytes, PARAMS_SIZE);
227
230
  });
228
231
  }
229
232
  has(key) {
@@ -269,4 +272,4 @@ var BinaryFuse16 = class BinaryFuse16 extends BinaryFuse {
269
272
  }
270
273
  };
271
274
  //#endregion
272
- export { BadMagicError, BinaryFuse16, BinaryFuse8, BinaryFuseBuildError, ChecksumError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, fuseBitsPerKey };
275
+ export { BadMagicError, BinaryFuse16, BinaryFuse8, BinaryFuseBuildError, ChecksumError, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, fuseBitsPerKey };
@@ -0,0 +1,230 @@
1
+ //#region src/core/bytes.ts
2
+ const encoder = new TextEncoder();
3
+ function normalize(input) {
4
+ if (typeof input === "string") return encoder.encode(input);
5
+ if (input instanceof Uint8Array) return input;
6
+ return new Uint8Array(input);
7
+ }
8
+ //#endregion
9
+ //#region src/core/hasher.ts
10
+ let RLO = 0;
11
+ let RHI = 0;
12
+ const LANES = {
13
+ w0: 0,
14
+ w1: 0,
15
+ w2: 0,
16
+ w3: 0
17
+ };
18
+ function mul64(alo, ahi, blo, bhi) {
19
+ const a0 = alo & 65535;
20
+ const a1 = alo >>> 16;
21
+ const a2 = ahi & 65535;
22
+ const a3 = ahi >>> 16;
23
+ const b0 = blo & 65535;
24
+ const b1 = blo >>> 16;
25
+ const b2 = bhi & 65535;
26
+ const b3 = bhi >>> 16;
27
+ let c0 = a0 * b0;
28
+ let c1 = c0 >>> 16;
29
+ c0 &= 65535;
30
+ c1 += a1 * b0;
31
+ let c2 = c1 >>> 16;
32
+ c1 &= 65535;
33
+ c1 += a0 * b1;
34
+ c2 += c1 >>> 16;
35
+ c1 &= 65535;
36
+ c2 += a2 * b0;
37
+ let c3 = c2 >>> 16;
38
+ c2 &= 65535;
39
+ c2 += a1 * b1;
40
+ c3 += c2 >>> 16;
41
+ c2 &= 65535;
42
+ c2 += a0 * b2;
43
+ c3 += c2 >>> 16;
44
+ c2 &= 65535;
45
+ c3 += a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3;
46
+ c3 &= 65535;
47
+ RLO = (c1 << 16 | c0) >>> 0;
48
+ RHI = (c3 << 16 | c2) >>> 0;
49
+ }
50
+ function fmix64(lo, hi) {
51
+ let l = lo;
52
+ let h = hi;
53
+ l = (l ^ h >>> 1) >>> 0;
54
+ mul64(l, h, 3981806797, 4283543511);
55
+ l = RLO;
56
+ h = RHI;
57
+ l = (l ^ h >>> 1) >>> 0;
58
+ mul64(l, h, 444984403, 3301882366);
59
+ l = RLO;
60
+ h = RHI;
61
+ l = (l ^ h >>> 1) >>> 0;
62
+ RLO = l;
63
+ RHI = h;
64
+ }
65
+ function rotl32(x, r) {
66
+ return (x << r | x >>> 32 - r) >>> 0;
67
+ }
68
+ function fmix32(h) {
69
+ let x = h;
70
+ x ^= x >>> 16;
71
+ x = Math.imul(x, 2246822507);
72
+ x ^= x >>> 13;
73
+ x = Math.imul(x, 3266489909);
74
+ x ^= x >>> 16;
75
+ return x >>> 0;
76
+ }
77
+ const K1 = 597399067;
78
+ const K2 = 2869860233;
79
+ const K3 = 951274213;
80
+ const K4 = 2716044179;
81
+ function computeLanes(bytes, seed, len) {
82
+ const nblocks = len >>> 4;
83
+ let h1 = seed >>> 0;
84
+ let h2 = seed >>> 0;
85
+ let h3 = seed >>> 0;
86
+ let h4 = seed >>> 0;
87
+ for (let i = 0; i < nblocks; i++) {
88
+ const b = i * 16;
89
+ let k1 = ((bytes[b] ?? 0) | (bytes[b + 1] ?? 0) << 8 | (bytes[b + 2] ?? 0) << 16 | (bytes[b + 3] ?? 0) << 24) >>> 0;
90
+ let k2 = ((bytes[b + 4] ?? 0) | (bytes[b + 5] ?? 0) << 8 | (bytes[b + 6] ?? 0) << 16 | (bytes[b + 7] ?? 0) << 24) >>> 0;
91
+ let k3 = ((bytes[b + 8] ?? 0) | (bytes[b + 9] ?? 0) << 8 | (bytes[b + 10] ?? 0) << 16 | (bytes[b + 11] ?? 0) << 24) >>> 0;
92
+ let k4 = ((bytes[b + 12] ?? 0) | (bytes[b + 13] ?? 0) << 8 | (bytes[b + 14] ?? 0) << 16 | (bytes[b + 15] ?? 0) << 24) >>> 0;
93
+ k1 = Math.imul(rotl32(Math.imul(k1, K1), 15), K2);
94
+ h1 ^= k1;
95
+ h1 = rotl32(h1, 19);
96
+ h1 = h1 + h2 >>> 0;
97
+ h1 = Math.imul(h1, 5) + 1444728091 >>> 0;
98
+ k2 = Math.imul(rotl32(Math.imul(k2, K2), 16), K3);
99
+ h2 ^= k2;
100
+ h2 = rotl32(h2, 17);
101
+ h2 = h2 + h3 >>> 0;
102
+ h2 = Math.imul(h2, 5) + 197830471 >>> 0;
103
+ k3 = Math.imul(rotl32(Math.imul(k3, K3), 17), K4);
104
+ h3 ^= k3;
105
+ h3 = rotl32(h3, 15);
106
+ h3 = h3 + h4 >>> 0;
107
+ h3 = Math.imul(h3, 5) + 2530024501 >>> 0;
108
+ k4 = Math.imul(rotl32(Math.imul(k4, K4), 18), K1);
109
+ h4 ^= k4;
110
+ h4 = rotl32(h4, 13);
111
+ h4 = h4 + h1 >>> 0;
112
+ h4 = Math.imul(h4, 5) + 850148119 >>> 0;
113
+ }
114
+ let k1 = 0;
115
+ let k2 = 0;
116
+ let k3 = 0;
117
+ let k4 = 0;
118
+ const tail = nblocks * 16;
119
+ const rem = len & 15;
120
+ if (rem >= 15) k4 ^= (bytes[tail + 14] ?? 0) << 16;
121
+ if (rem >= 14) k4 ^= (bytes[tail + 13] ?? 0) << 8;
122
+ if (rem >= 13) {
123
+ k4 ^= bytes[tail + 12] ?? 0;
124
+ k4 = Math.imul(rotl32(Math.imul(k4, K4), 18), K1);
125
+ h4 ^= k4;
126
+ }
127
+ if (rem >= 12) k3 ^= (bytes[tail + 11] ?? 0) << 24;
128
+ if (rem >= 11) k3 ^= (bytes[tail + 10] ?? 0) << 16;
129
+ if (rem >= 10) k3 ^= (bytes[tail + 9] ?? 0) << 8;
130
+ if (rem >= 9) {
131
+ k3 ^= bytes[tail + 8] ?? 0;
132
+ k3 = Math.imul(rotl32(Math.imul(k3, K3), 17), K4);
133
+ h3 ^= k3;
134
+ }
135
+ if (rem >= 8) k2 ^= (bytes[tail + 7] ?? 0) << 24;
136
+ if (rem >= 7) k2 ^= (bytes[tail + 6] ?? 0) << 16;
137
+ if (rem >= 6) k2 ^= (bytes[tail + 5] ?? 0) << 8;
138
+ if (rem >= 5) {
139
+ k2 ^= bytes[tail + 4] ?? 0;
140
+ k2 = Math.imul(rotl32(Math.imul(k2, K2), 16), K3);
141
+ h2 ^= k2;
142
+ }
143
+ if (rem >= 4) k1 ^= (bytes[tail + 3] ?? 0) << 24;
144
+ if (rem >= 3) k1 ^= (bytes[tail + 2] ?? 0) << 16;
145
+ if (rem >= 2) k1 ^= (bytes[tail + 1] ?? 0) << 8;
146
+ if (rem >= 1) {
147
+ k1 ^= bytes[tail] ?? 0;
148
+ k1 = Math.imul(rotl32(Math.imul(k1, K1), 15), K2);
149
+ h1 ^= k1;
150
+ }
151
+ h1 = (h1 ^ len) >>> 0;
152
+ h2 = (h2 ^ len) >>> 0;
153
+ h3 = (h3 ^ len) >>> 0;
154
+ h4 = (h4 ^ len) >>> 0;
155
+ h1 = h1 + h2 >>> 0;
156
+ h1 = h1 + h3 >>> 0;
157
+ h1 = h1 + h4 >>> 0;
158
+ h2 = h2 + h1 >>> 0;
159
+ h3 = h3 + h1 >>> 0;
160
+ h4 = h4 + h1 >>> 0;
161
+ h1 = fmix32(h1);
162
+ h2 = fmix32(h2);
163
+ h3 = fmix32(h3);
164
+ h4 = fmix32(h4);
165
+ h1 = h1 + h2 >>> 0;
166
+ h1 = h1 + h3 >>> 0;
167
+ h1 = h1 + h4 >>> 0;
168
+ h2 = h2 + h1 >>> 0;
169
+ h3 = h3 + h1 >>> 0;
170
+ h4 = h4 + h1 >>> 0;
171
+ LANES.w0 = h1;
172
+ LANES.w1 = h2;
173
+ LANES.w2 = h3;
174
+ LANES.w3 = h4;
175
+ }
176
+ const keyEncoder = new TextEncoder();
177
+ let keyBuf = new Uint8Array(256);
178
+ let encBytes = keyBuf;
179
+ let encLen = 0;
180
+ function encodeKey(key) {
181
+ if (typeof key === "string") {
182
+ const cap = key.length * 3;
183
+ if (keyBuf.length < cap) keyBuf = new Uint8Array(cap);
184
+ encLen = keyEncoder.encodeInto(key, keyBuf).written;
185
+ encBytes = keyBuf;
186
+ return;
187
+ }
188
+ encBytes = normalize(key);
189
+ encLen = encBytes.length;
190
+ }
191
+ function keyToLanes(key, seed) {
192
+ encodeKey(key);
193
+ computeLanes(encBytes, seed, encLen);
194
+ }
195
+ function hash128KeyInto(key, seed, out) {
196
+ keyToLanes(key, seed);
197
+ out.w0 = LANES.w0;
198
+ out.w1 = LANES.w1;
199
+ out.w2 = LANES.w2;
200
+ out.w3 = LANES.w3;
201
+ }
202
+ function reduce(x, range) {
203
+ const xlo = x & 65535;
204
+ const xhi = x >>> 16;
205
+ const rlo = range & 65535;
206
+ const rhi = range >>> 16;
207
+ const lolo = xlo * rlo;
208
+ const lohi = xlo * rhi;
209
+ const hilo = xhi * rlo;
210
+ const hihi = xhi * rhi;
211
+ const carry = (lolo >>> 16) + (lohi & 65535) + (hilo & 65535);
212
+ return hihi + (lohi >>> 16) + (hilo >>> 16) + (carry >>> 16) >>> 0;
213
+ }
214
+ function hash32x2Into(key, seed, out) {
215
+ keyToLanes(key, seed);
216
+ out[0] = LANES.w0;
217
+ out[1] = LANES.w1;
218
+ }
219
+ function probeAt(a, b, i, range) {
220
+ return reduce(a + Math.imul(i, b) + i * i >>> 0, range);
221
+ }
222
+ function probeLanesInto(a, b, count, range, out) {
223
+ for (let i = 0; i < count; i++) out[i] = probeAt(a, b, i, range);
224
+ }
225
+ function probeInto(key, count, range, seed, out) {
226
+ keyToLanes(key, seed);
227
+ probeLanesInto(LANES.w0, LANES.w1, count, range, out);
228
+ }
229
+ //#endregion
230
+ export { hash32x2Into as a, probeInto as c, hash128KeyInto as i, probeLanesInto as l, RLO as n, mul64 as o, fmix64 as r, probeAt as s, RHI as t, reduce as u };