distillate 0.9.0 → 0.10.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/README.md CHANGED
@@ -135,6 +135,25 @@ Classic Bloom head-to-head at a **matched 1% false-positive rate** over the same
135
135
 
136
136
  Same space, same accuracy, **~75x the lookup throughput** of [`bloom-filters`](https://www.npmjs.com/package/bloom-filters) (the package distillate replaces), while hashing UTF-8 bytes with MurmurHash3 so filters stay portable and cross-language readable.
137
137
 
138
+ Cardinality is a separate head-to-head, at a **matched register count** (`m = 2 ** p`, `p = 14`, the configuration Redis uses) over the same keys, swept from 1k to 10M distinct:
139
+
140
+ | p = 14, m = 16384 | distillate | bloom-filters |
141
+ | -------------------- | --------------- | ---------------- |
142
+ | rel. error, n=1k | 0.00% | 49.63% |
143
+ | rel. error, n=100k | 0.82% | 0.78% |
144
+ | rel. error, n=10M | 0.15% | 0.41% |
145
+ | serialized, n=10M | 12,314 B binary | 40,247 B JSON |
146
+ | build 10M keys | 0.63 s | 1,165 s (19 min) |
147
+ | sustained add, n=10M | ~16 M ops/s | ~9 k ops/s |
148
+
149
+ Both sketches carry the same theoretical error at this precision (`1.04 / sqrt(m)`, about 0.81%), and once `n` is well past `m` both stay inside it. The differences are elsewhere.
150
+
151
+ **Small counts.** `bloom-filters` has no working small-range correction, so below roughly `2.5 * m` it is off by about half: counting a few thousand distinct keys in a 16k-register sketch, it answers 504 for 1,000. distillate is exact there because it is still holding sparse entries, not because its estimator is better.
152
+
153
+ **Memory does not grow.** From 10k distinct keys to 10M, distillate stays at exactly 12,314 bytes. The incumbent's JSON grows from 32,904 to 40,247 bytes over the same range, because larger register values take more digits to spell out.
154
+
155
+ **Building the sketch.** `bloom-filters` holds a flat 9k adds/sec at every size, so its cost is purely linear: 10.6 seconds for 100k distinct keys, 109 seconds for 1M, and 1,165 seconds for 10M. distillate counts the same 10M in 0.63 seconds, and its rate climbs with `n` rather than staying flat, reaching about 16 M ops/s once the registers are dense.
156
+
138
157
  These are a point-in-time snapshot on one machine. The full report (blocked/fuse, 1M capacity, the `bloomfilter` micro-package) and exactly how it is measured live in the [`apps/bench`](https://github.com/akshay-xp/distillate/tree/main/apps/bench) workspace: [RESULTS.md](https://github.com/akshay-xp/distillate/blob/main/apps/bench/RESULTS.md), [METHODOLOGY.md](https://github.com/akshay-xp/distillate/blob/main/apps/bench/METHODOLOGY.md).
139
158
 
140
159
  ## Docs
@@ -1,8 +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-D8LCBTOM.cjs");
3
+ const require_serialize = require("../serialize-CHikZ4GH.cjs");
3
4
  const require_params = require("../params-UTZbJ22c.cjs");
4
5
  //#region src/blocked/blocked.ts
5
6
  const TYPE = 2;
7
+ const PARAMS_SIZE = 16;
8
+ const PARAMS_FIELDS_END = 12;
6
9
  const SALT = Uint32Array.of(1203114875, 1150766481, 2284105051, 2729912477, 1884591559, 770785867, 2667333959, 1550580529);
7
10
  const scratch2 = new Uint32Array(2);
8
11
  const BLOCK_BITS = 256;
@@ -91,28 +94,29 @@ var BlockedBloomFilter = class BlockedBloomFilter {
91
94
  const { type, flags, body } = require_serialize.readHeader(bytes);
92
95
  if (type !== TYPE) throw new require_serialize.SerializationError(`expected DSTL type ${String(TYPE)}, got ${String(type)}`);
93
96
  if ((flags & 15) !== 0) throw new require_serialize.UnknownHashVariantError(`unsupported hash variant ${String(flags & 15)}`);
94
- require_serialize.assertMinBodyLength(body.length, 12, "blocked");
97
+ require_serialize.assertMinBodyLength(body.length, PARAMS_SIZE, "blocked");
98
+ require_serialize.assertParamsPadding(body, PARAMS_FIELDS_END, PARAMS_SIZE, "blocked");
95
99
  const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
96
100
  const numBlocks = dv.getUint32(0, true);
97
101
  const seed = dv.getUint32(4, true);
98
102
  const n = dv.getUint32(8, true);
99
103
  if (numBlocks === 0 || n === 0) throw new require_serialize.SerializationError(`blocked frame declares numBlocks=${String(numBlocks)}, n=${String(n)}; both must be positive`);
100
- require_serialize.assertBodyLength(body.length, 12 + numBlocks * 32, "blocked");
104
+ require_serialize.assertBodyLength(body.length, PARAMS_SIZE + numBlocks * 32, "blocked");
101
105
  const f = BlockedBloomFilter.#fromNumBlocks(numBlocks, seed, n);
102
- new Uint8Array(f.#lanes.buffer).set(body.subarray(12));
106
+ new Uint8Array(f.#lanes.buffer).set(body.subarray(PARAMS_SIZE));
103
107
  return f;
104
108
  }
105
109
  toBytes() {
106
110
  const lanes = new Uint8Array(this.#lanes.buffer, this.#lanes.byteOffset, this.#lanes.byteLength);
107
111
  return require_serialize.writeFrame({
108
- version: 4,
112
+ version: 5,
109
113
  type: TYPE,
110
114
  flags: 0
111
- }, 12 + lanes.length, (body, dv) => {
115
+ }, PARAMS_SIZE, lanes.length, (body, dv) => {
112
116
  dv.setUint32(0, this.#numBlocks, true);
113
117
  dv.setUint32(4, this.#seed, true);
114
118
  dv.setUint32(8, this.#n, true);
115
- body.set(lanes, 12);
119
+ body.set(lanes, PARAMS_SIZE);
116
120
  });
117
121
  }
118
122
  equals(other) {
@@ -147,8 +151,8 @@ var BlockedBloomFilter = class BlockedBloomFilter {
147
151
  }
148
152
  };
149
153
  function fillBlock(key, numBlocks, seed, outWords, outBits) {
150
- require_serialize.hash32x2Into(key, seed, scratch2);
151
- const block = require_serialize.reduce(scratch2[0] ?? 0, numBlocks);
154
+ require_hasher.hash32x2Into(key, seed, scratch2);
155
+ const block = require_hasher.reduce(scratch2[0] ?? 0, numBlocks);
152
156
  const x = scratch2[1] ?? 0;
153
157
  const base = block * 8;
154
158
  for (let i = 0; i < 8; i++) {
@@ -162,6 +166,7 @@ exports.BlockedBloomFilter = BlockedBloomFilter;
162
166
  exports.BlockedBloomParamMismatchError = BlockedBloomParamMismatchError;
163
167
  exports.ChecksumError = require_serialize.ChecksumError;
164
168
  exports.ParamError = require_params.ParamError;
169
+ exports.ReservedBitsError = require_serialize.ReservedBitsError;
165
170
  exports.SerializationError = require_serialize.SerializationError;
166
171
  exports.TruncatedError = require_serialize.TruncatedError;
167
172
  exports.UnknownHashVariantError = require_serialize.UnknownHashVariantError;
@@ -1,4 +1,5 @@
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
  import { t as ParamError } from "../params-DnqJBqLS.cjs";
3
4
  //#region src/blocked/blocked.d.ts
4
5
  /**
@@ -8,16 +9,16 @@ import { t as ParamError } from "../params-DnqJBqLS.cjs";
8
9
  * `lambda = 256 / bitsPerKey`. This clustering average is why the blocked curve
9
10
  * is not linear in `log10(1/epsilon)`.
10
11
  */
11
- declare function blockedFprAt(bitsPerKey: number): number;
12
+ export declare function blockedFprAt(bitsPerKey: number): number;
12
13
  /**
13
14
  * Minimal integer bits-per-key whose modeled split-block FPR is at or below
14
15
  * `epsilon`. Throws {@link ParamError} when even the densest supported filter
15
16
  * cannot reach the target, so callers get a typed rejection instead of a
16
17
  * silently under-provisioned filter.
17
18
  */
18
- declare function blockedBitsPerKey(epsilon: number): number;
19
+ export declare function blockedBitsPerKey(epsilon: number): number;
19
20
  /** Thrown when an operation requires two filters built with identical parameters. */
20
- declare class BlockedBloomParamMismatchError extends Error {
21
+ export declare class BlockedBloomParamMismatchError extends Error {
21
22
  /** Discriminates this error from other `Error`s. */
22
23
  override readonly name = "BlockedBloomParamMismatchError";
23
24
  }
@@ -41,7 +42,7 @@ interface BlockedBloomParams {
41
42
  * filter.has("alice"); // true
42
43
  * ```
43
44
  */
44
- declare class BlockedBloomFilter {
45
+ export declare class BlockedBloomFilter {
45
46
  #private;
46
47
  /**
47
48
  * Creates a filter sized for `n` expected keys at a target false-positive rate.
@@ -142,4 +143,4 @@ declare class BlockedBloomFilter {
142
143
  has(key: BytesLike): boolean;
143
144
  }
144
145
  //#endregion
145
- export { BadMagicError, BlockedBloomFilter, BlockedBloomParamMismatchError, type BlockedBloomParams, ChecksumError, type FilterJSON, ParamError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, blockedBitsPerKey, blockedFprAt };
146
+ export { BadMagicError, type BlockedBloomParams, ChecksumError, type FilterJSON, ParamError, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError };
@@ -1,4 +1,5 @@
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
  import { t as ParamError } from "../params-DnqJBqLS.js";
3
4
  //#region src/blocked/blocked.d.ts
4
5
  /**
@@ -8,16 +9,16 @@ import { t as ParamError } from "../params-DnqJBqLS.js";
8
9
  * `lambda = 256 / bitsPerKey`. This clustering average is why the blocked curve
9
10
  * is not linear in `log10(1/epsilon)`.
10
11
  */
11
- declare function blockedFprAt(bitsPerKey: number): number;
12
+ export declare function blockedFprAt(bitsPerKey: number): number;
12
13
  /**
13
14
  * Minimal integer bits-per-key whose modeled split-block FPR is at or below
14
15
  * `epsilon`. Throws {@link ParamError} when even the densest supported filter
15
16
  * cannot reach the target, so callers get a typed rejection instead of a
16
17
  * silently under-provisioned filter.
17
18
  */
18
- declare function blockedBitsPerKey(epsilon: number): number;
19
+ export declare function blockedBitsPerKey(epsilon: number): number;
19
20
  /** Thrown when an operation requires two filters built with identical parameters. */
20
- declare class BlockedBloomParamMismatchError extends Error {
21
+ export declare class BlockedBloomParamMismatchError extends Error {
21
22
  /** Discriminates this error from other `Error`s. */
22
23
  override readonly name = "BlockedBloomParamMismatchError";
23
24
  }
@@ -41,7 +42,7 @@ interface BlockedBloomParams {
41
42
  * filter.has("alice"); // true
42
43
  * ```
43
44
  */
44
- declare class BlockedBloomFilter {
45
+ export declare class BlockedBloomFilter {
45
46
  #private;
46
47
  /**
47
48
  * Creates a filter sized for `n` expected keys at a target false-positive rate.
@@ -142,4 +143,4 @@ declare class BlockedBloomFilter {
142
143
  has(key: BytesLike): boolean;
143
144
  }
144
145
  //#endregion
145
- export { BadMagicError, BlockedBloomFilter, BlockedBloomParamMismatchError, type BlockedBloomParams, ChecksumError, type FilterJSON, ParamError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, blockedBitsPerKey, blockedFprAt };
146
+ export { BadMagicError, type BlockedBloomParams, ChecksumError, type FilterJSON, ParamError, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError };
@@ -1,7 +1,10 @@
1
- import { a as UnknownHashVariantError, c as assertMinBodyLength, d as readHeader, f as toJSONEnvelope, i as TruncatedError, l as bytesEqual, n as ChecksumError, o as UnknownVersionError, p as writeFrame, r as SerializationError, s as assertBodyLength, t as BadMagicError, u as fromJSONEnvelope, v as hash32x2Into, x as reduce } from "../serialize-D59Ri81a.js";
1
+ import { a as hash32x2Into, c as reduce } from "../hasher-DVWXS_vJ.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, u as assertParamsPadding } from "../serialize-CMSYFym-.js";
2
3
  import { i as assertProbability, n as assertPositiveFinite, o as assertUint32, r as assertPositiveInt, t as ParamError } from "../params-CeajSrwv.js";
3
4
  //#region src/blocked/blocked.ts
4
5
  const TYPE = 2;
6
+ const PARAMS_SIZE = 16;
7
+ const PARAMS_FIELDS_END = 12;
5
8
  const SALT = Uint32Array.of(1203114875, 1150766481, 2284105051, 2729912477, 1884591559, 770785867, 2667333959, 1550580529);
6
9
  const scratch2 = new Uint32Array(2);
7
10
  const BLOCK_BITS = 256;
@@ -90,28 +93,29 @@ var BlockedBloomFilter = class BlockedBloomFilter {
90
93
  const { type, flags, body } = readHeader(bytes);
91
94
  if (type !== TYPE) throw new SerializationError(`expected DSTL type ${String(TYPE)}, got ${String(type)}`);
92
95
  if ((flags & 15) !== 0) throw new UnknownHashVariantError(`unsupported hash variant ${String(flags & 15)}`);
93
- assertMinBodyLength(body.length, 12, "blocked");
96
+ assertMinBodyLength(body.length, PARAMS_SIZE, "blocked");
97
+ assertParamsPadding(body, PARAMS_FIELDS_END, PARAMS_SIZE, "blocked");
94
98
  const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
95
99
  const numBlocks = dv.getUint32(0, true);
96
100
  const seed = dv.getUint32(4, true);
97
101
  const n = dv.getUint32(8, true);
98
102
  if (numBlocks === 0 || n === 0) throw new SerializationError(`blocked frame declares numBlocks=${String(numBlocks)}, n=${String(n)}; both must be positive`);
99
- assertBodyLength(body.length, 12 + numBlocks * 32, "blocked");
103
+ assertBodyLength(body.length, PARAMS_SIZE + numBlocks * 32, "blocked");
100
104
  const f = BlockedBloomFilter.#fromNumBlocks(numBlocks, seed, n);
101
- new Uint8Array(f.#lanes.buffer).set(body.subarray(12));
105
+ new Uint8Array(f.#lanes.buffer).set(body.subarray(PARAMS_SIZE));
102
106
  return f;
103
107
  }
104
108
  toBytes() {
105
109
  const lanes = new Uint8Array(this.#lanes.buffer, this.#lanes.byteOffset, this.#lanes.byteLength);
106
110
  return writeFrame({
107
- version: 4,
111
+ version: 5,
108
112
  type: TYPE,
109
113
  flags: 0
110
- }, 12 + lanes.length, (body, dv) => {
114
+ }, PARAMS_SIZE, lanes.length, (body, dv) => {
111
115
  dv.setUint32(0, this.#numBlocks, true);
112
116
  dv.setUint32(4, this.#seed, true);
113
117
  dv.setUint32(8, this.#n, true);
114
- body.set(lanes, 12);
118
+ body.set(lanes, PARAMS_SIZE);
115
119
  });
116
120
  }
117
121
  equals(other) {
@@ -156,4 +160,4 @@ function fillBlock(key, numBlocks, seed, outWords, outBits) {
156
160
  }
157
161
  }
158
162
  //#endregion
159
- export { BadMagicError, BlockedBloomFilter, BlockedBloomParamMismatchError, ChecksumError, ParamError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, blockedBitsPerKey, blockedFprAt };
163
+ export { BadMagicError, BlockedBloomFilter, BlockedBloomParamMismatchError, ChecksumError, ParamError, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, blockedBitsPerKey, blockedFprAt };
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_serialize = require("../serialize-Ul2LKFJU.cjs");
2
+ const require_hasher = require("../hasher-D8LCBTOM.cjs");
3
+ const require_serialize = require("../serialize-CHikZ4GH.cjs");
3
4
  const require_params = require("../params-UTZbJ22c.cjs");
4
5
  const require_sizing = require("../sizing-BLzZk2zr.cjs");
5
6
  //#region src/core/bitset.ts
@@ -35,6 +36,8 @@ var BitSet = class {
35
36
  //#endregion
36
37
  //#region src/bloom/bloom.ts
37
38
  const TYPE = 1;
39
+ const PARAMS_SIZE = 16;
40
+ const PARAMS_FIELDS_END = 14;
38
41
  var BloomParamMismatchError = class extends Error {
39
42
  name = "BloomParamMismatchError";
40
43
  };
@@ -64,20 +67,21 @@ var BloomFilter = class BloomFilter {
64
67
  const { type, flags, body } = require_serialize.readHeader(bytes);
65
68
  if (type !== TYPE) throw new require_serialize.SerializationError(`expected DSTL type ${String(TYPE)}, got ${String(type)}`);
66
69
  if ((flags & 15) !== 0) throw new require_serialize.UnknownHashVariantError(`unsupported hash variant ${String(flags & 15)}`);
67
- require_serialize.assertMinBodyLength(body.length, 14, "bloom");
70
+ require_serialize.assertMinBodyLength(body.length, PARAMS_SIZE, "bloom");
71
+ require_serialize.assertParamsPadding(body, PARAMS_FIELDS_END, PARAMS_SIZE, "bloom");
68
72
  const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
69
73
  const m = dv.getUint32(0, true);
70
74
  const k = dv.getUint16(4, true);
71
75
  const seed = dv.getUint32(6, true);
72
76
  const n = dv.getUint32(10, true);
73
- require_serialize.assertBodyLength(body.length, 14 + Math.ceil(m / 8), "bloom");
77
+ require_serialize.assertBodyLength(body.length, PARAMS_SIZE + Math.ceil(m / 8), "bloom");
74
78
  const f = new BloomFilter({
75
79
  m,
76
80
  k,
77
81
  seed,
78
82
  n
79
83
  });
80
- f.#bits.bytes.set(body.subarray(14));
84
+ f.#bits.bytes.set(body.subarray(PARAMS_SIZE));
81
85
  return f;
82
86
  }
83
87
  constructor({ m, k, seed = 0, n }) {
@@ -118,15 +122,15 @@ var BloomFilter = class BloomFilter {
118
122
  toBytes() {
119
123
  const payload = this.#bits.bytes;
120
124
  return require_serialize.writeFrame({
121
- version: 4,
125
+ version: 5,
122
126
  type: TYPE,
123
127
  flags: 0
124
- }, 14 + payload.length, (body, dv) => {
128
+ }, PARAMS_SIZE, payload.length, (body, dv) => {
125
129
  dv.setUint32(0, this.#m, true);
126
130
  dv.setUint16(4, this.#k, true);
127
131
  dv.setUint32(6, this.#seed, true);
128
132
  dv.setUint32(10, this.#n, true);
129
- body.set(payload, 14);
133
+ body.set(payload, PARAMS_SIZE);
130
134
  });
131
135
  }
132
136
  equals(other) {
@@ -154,11 +158,11 @@ var BloomFilter = class BloomFilter {
154
158
  return r;
155
159
  }
156
160
  add(key) {
157
- require_serialize.probeInto(key, this.#k, this.#m, this.#seed, this.#scratch);
161
+ require_hasher.probeInto(key, this.#k, this.#m, this.#seed, this.#scratch);
158
162
  for (let i = 0; i < this.#k; i++) this.#bits.set(this.#scratch[i] ?? 0);
159
163
  }
160
164
  has(key) {
161
- require_serialize.probeInto(key, this.#k, this.#m, this.#seed, this.#scratch);
165
+ require_hasher.probeInto(key, this.#k, this.#m, this.#seed, this.#scratch);
162
166
  for (let i = 0; i < this.#k; i++) if (!this.#bits.get(this.#scratch[i] ?? 0)) return false;
163
167
  return true;
164
168
  }
@@ -169,6 +173,7 @@ exports.BloomFilter = BloomFilter;
169
173
  exports.BloomParamMismatchError = BloomParamMismatchError;
170
174
  exports.ChecksumError = require_serialize.ChecksumError;
171
175
  exports.ParamError = require_params.ParamError;
176
+ exports.ReservedBitsError = require_serialize.ReservedBitsError;
172
177
  exports.SerializationError = require_serialize.SerializationError;
173
178
  exports.TruncatedError = require_serialize.TruncatedError;
174
179
  exports.UnknownHashVariantError = require_serialize.UnknownHashVariantError;
@@ -1,9 +1,10 @@
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
  import { t as ParamError } from "../params-DnqJBqLS.cjs";
3
4
  import { r as bloomSizing, t as BloomSizing } from "../sizing-wYOW27eY.cjs";
4
5
  //#region src/bloom/bloom.d.ts
5
6
  /** Thrown when an operation requires two filters built with identical parameters. */
6
- declare class BloomParamMismatchError extends Error {
7
+ export declare class BloomParamMismatchError extends Error {
7
8
  /** Discriminates this error from other `Error`s. */
8
9
  override readonly name = "BloomParamMismatchError";
9
10
  }
@@ -34,7 +35,7 @@ interface BloomParams {
34
35
  * filter.has("bob"); // false (or a ~1% false positive)
35
36
  * ```
36
37
  */
37
- declare class BloomFilter {
38
+ export declare class BloomFilter {
38
39
  #private;
39
40
  /**
40
41
  * Creates a filter sized for `n` expected keys at a target false-positive rate.
@@ -143,4 +144,4 @@ declare class BloomFilter {
143
144
  has(key: BytesLike): boolean;
144
145
  }
145
146
  //#endregion
146
- export { BadMagicError, BloomFilter, BloomParamMismatchError, type BloomParams, type BloomSizing, ChecksumError, type FilterJSON, ParamError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, bloomSizing };
147
+ export { BadMagicError, type BloomParams, type BloomSizing, ChecksumError, type FilterJSON, ParamError, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, bloomSizing };
@@ -1,9 +1,10 @@
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
  import { t as ParamError } from "../params-DnqJBqLS.js";
3
4
  import { r as bloomSizing, t as BloomSizing } from "../sizing-wYOW27eY.js";
4
5
  //#region src/bloom/bloom.d.ts
5
6
  /** Thrown when an operation requires two filters built with identical parameters. */
6
- declare class BloomParamMismatchError extends Error {
7
+ export declare class BloomParamMismatchError extends Error {
7
8
  /** Discriminates this error from other `Error`s. */
8
9
  override readonly name = "BloomParamMismatchError";
9
10
  }
@@ -34,7 +35,7 @@ interface BloomParams {
34
35
  * filter.has("bob"); // false (or a ~1% false positive)
35
36
  * ```
36
37
  */
37
- declare class BloomFilter {
38
+ export declare class BloomFilter {
38
39
  #private;
39
40
  /**
40
41
  * Creates a filter sized for `n` expected keys at a target false-positive rate.
@@ -143,4 +144,4 @@ declare class BloomFilter {
143
144
  has(key: BytesLike): boolean;
144
145
  }
145
146
  //#endregion
146
- export { BadMagicError, BloomFilter, BloomParamMismatchError, type BloomParams, type BloomSizing, ChecksumError, type FilterJSON, ParamError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, bloomSizing };
147
+ export { BadMagicError, type BloomParams, type BloomSizing, ChecksumError, type FilterJSON, ParamError, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, bloomSizing };
@@ -1,4 +1,5 @@
1
- import { a as UnknownHashVariantError, b as probeInto, c as assertMinBodyLength, d as readHeader, f as toJSONEnvelope, i as TruncatedError, l as bytesEqual, n as ChecksumError, o as UnknownVersionError, p as writeFrame, r as SerializationError, s as assertBodyLength, t as BadMagicError, u as fromJSONEnvelope } from "../serialize-D59Ri81a.js";
1
+ import { s as probeInto } from "../hasher-DVWXS_vJ.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, u as assertParamsPadding } from "../serialize-CMSYFym-.js";
2
3
  import { a as assertUint16, i as assertProbability, o as assertUint32, r as assertPositiveInt, t as ParamError } from "../params-CeajSrwv.js";
3
4
  import { t as bloomSizing } from "../sizing-BtUrtvF_.js";
4
5
  //#region src/core/bitset.ts
@@ -34,6 +35,8 @@ var BitSet = class {
34
35
  //#endregion
35
36
  //#region src/bloom/bloom.ts
36
37
  const TYPE = 1;
38
+ const PARAMS_SIZE = 16;
39
+ const PARAMS_FIELDS_END = 14;
37
40
  var BloomParamMismatchError = class extends Error {
38
41
  name = "BloomParamMismatchError";
39
42
  };
@@ -63,20 +66,21 @@ var BloomFilter = class BloomFilter {
63
66
  const { type, flags, body } = readHeader(bytes);
64
67
  if (type !== TYPE) throw new SerializationError(`expected DSTL type ${String(TYPE)}, got ${String(type)}`);
65
68
  if ((flags & 15) !== 0) throw new UnknownHashVariantError(`unsupported hash variant ${String(flags & 15)}`);
66
- assertMinBodyLength(body.length, 14, "bloom");
69
+ assertMinBodyLength(body.length, PARAMS_SIZE, "bloom");
70
+ assertParamsPadding(body, PARAMS_FIELDS_END, PARAMS_SIZE, "bloom");
67
71
  const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
68
72
  const m = dv.getUint32(0, true);
69
73
  const k = dv.getUint16(4, true);
70
74
  const seed = dv.getUint32(6, true);
71
75
  const n = dv.getUint32(10, true);
72
- assertBodyLength(body.length, 14 + Math.ceil(m / 8), "bloom");
76
+ assertBodyLength(body.length, PARAMS_SIZE + Math.ceil(m / 8), "bloom");
73
77
  const f = new BloomFilter({
74
78
  m,
75
79
  k,
76
80
  seed,
77
81
  n
78
82
  });
79
- f.#bits.bytes.set(body.subarray(14));
83
+ f.#bits.bytes.set(body.subarray(PARAMS_SIZE));
80
84
  return f;
81
85
  }
82
86
  constructor({ m, k, seed = 0, n }) {
@@ -117,15 +121,15 @@ var BloomFilter = class BloomFilter {
117
121
  toBytes() {
118
122
  const payload = this.#bits.bytes;
119
123
  return writeFrame({
120
- version: 4,
124
+ version: 5,
121
125
  type: TYPE,
122
126
  flags: 0
123
- }, 14 + payload.length, (body, dv) => {
127
+ }, PARAMS_SIZE, payload.length, (body, dv) => {
124
128
  dv.setUint32(0, this.#m, true);
125
129
  dv.setUint16(4, this.#k, true);
126
130
  dv.setUint32(6, this.#seed, true);
127
131
  dv.setUint32(10, this.#n, true);
128
- body.set(payload, 14);
132
+ body.set(payload, PARAMS_SIZE);
129
133
  });
130
134
  }
131
135
  equals(other) {
@@ -163,4 +167,4 @@ var BloomFilter = class BloomFilter {
163
167
  }
164
168
  };
165
169
  //#endregion
166
- export { BadMagicError, BloomFilter, BloomParamMismatchError, ChecksumError, ParamError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, bloomSizing };
170
+ export { BadMagicError, BloomFilter, BloomParamMismatchError, ChecksumError, ParamError, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError, bloomSizing };
@@ -0,0 +1,4 @@
1
+ //#region src/core/bytes.d.ts
2
+ type BytesLike = string | Uint8Array | ArrayBuffer;
3
+ //#endregion
4
+ export { BytesLike as t };
@@ -0,0 +1,4 @@
1
+ //#region src/core/bytes.d.ts
2
+ type BytesLike = string | Uint8Array | ArrayBuffer;
3
+ //#endregion
4
+ export { BytesLike as t };
@@ -0,0 +1,9 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_serialize = require("../serialize-CHikZ4GH.cjs");
3
+ exports.BadMagicError = require_serialize.BadMagicError;
4
+ exports.ChecksumError = require_serialize.ChecksumError;
5
+ exports.ReservedBitsError = require_serialize.ReservedBitsError;
6
+ exports.SerializationError = require_serialize.SerializationError;
7
+ exports.TruncatedError = require_serialize.TruncatedError;
8
+ exports.UnknownVersionError = require_serialize.UnknownVersionError;
9
+ exports.readFrameAt = require_serialize.readFrameAt;
@@ -0,0 +1,2 @@
1
+ import { a as ReservedBitsError, i as Frame, l as UnknownVersionError, n as ChecksumError, o as SerializationError, s as TruncatedError, t as BadMagicError, u as readFrameAt } from "../serialize--xR6vGSW.cjs";
2
+ export { BadMagicError, ChecksumError, type Frame, ReservedBitsError, SerializationError, TruncatedError, UnknownVersionError, readFrameAt };
@@ -0,0 +1,2 @@
1
+ import { a as ReservedBitsError, i as Frame, l as UnknownVersionError, n as ChecksumError, o as SerializationError, s as TruncatedError, t as BadMagicError, u as readFrameAt } from "../serialize--xR6vGSW.js";
2
+ export { BadMagicError, ChecksumError, type Frame, ReservedBitsError, SerializationError, TruncatedError, UnknownVersionError, readFrameAt };
@@ -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-D8LCBTOM.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 };