distillate 0.8.2 → 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 +53 -6
- package/dist/blocked/index.cjs +15 -10
- package/dist/blocked/index.d.cts +7 -6
- package/dist/blocked/index.d.ts +7 -6
- package/dist/blocked/index.js +13 -9
- package/dist/bloom/index.cjs +35 -34
- package/dist/bloom/index.d.cts +22 -17
- package/dist/bloom/index.d.ts +22 -17
- package/dist/bloom/index.js +32 -32
- package/dist/bytes-DCuYtUVS.d.cts +4 -0
- package/dist/bytes-DCuYtUVS.d.ts +4 -0
- package/dist/frame/index.cjs +9 -0
- package/dist/frame/index.d.cts +2 -0
- package/dist/frame/index.d.ts +2 -0
- package/dist/frame/index.js +2 -0
- package/dist/fuse/index.cjs +27 -23
- package/dist/fuse/index.d.cts +7 -6
- package/dist/fuse/index.d.ts +7 -6
- package/dist/fuse/index.js +15 -12
- package/dist/hasher-D8LCBTOM.cjs +276 -0
- package/dist/hasher-DVWXS_vJ.js +229 -0
- package/dist/hll/index.cjs +366 -0
- package/dist/hll/index.d.cts +120 -0
- package/dist/hll/index.d.ts +120 -0
- package/dist/hll/index.js +356 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -1
- package/dist/serialize--xR6vGSW.d.cts +112 -0
- package/dist/serialize--xR6vGSW.d.ts +112 -0
- package/dist/serialize-CHikZ4GH.cjs +296 -0
- package/dist/serialize-CMSYFym-.js +201 -0
- package/dist/sizing-BLzZk2zr.cjs +28 -0
- package/dist/sizing-BtUrtvF_.js +17 -0
- package/dist/sizing-wYOW27eY.d.cts +22 -0
- package/dist/sizing-wYOW27eY.d.ts +22 -0
- package/package.json +26 -10
- package/dist/serialize-BqIcsR2J.js +0 -388
- package/dist/serialize-CXnRWItH.cjs +0 -513
- package/dist/serialize-ChyWpB9F.d.cts +0 -73
- package/dist/serialize-ChyWpB9F.d.ts +0 -73
package/dist/bloom/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
4
|
+
import { t as bloomSizing } from "../sizing-BtUrtvF_.js";
|
|
3
5
|
//#region src/core/bitset.ts
|
|
4
6
|
var BitSetRangeError = class extends RangeError {
|
|
5
7
|
name = "BitSetRangeError";
|
|
@@ -31,17 +33,10 @@ var BitSet = class {
|
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
//#endregion
|
|
34
|
-
//#region src/core/sizing.ts
|
|
35
|
-
function bloomSizing(n, epsilon) {
|
|
36
|
-
const m = Math.ceil(-n * Math.log(epsilon) / (Math.LN2 * Math.LN2));
|
|
37
|
-
return {
|
|
38
|
-
m,
|
|
39
|
-
k: Math.max(1, Math.round(m / n * Math.LN2))
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
36
|
//#region src/bloom/bloom.ts
|
|
44
37
|
const TYPE = 1;
|
|
38
|
+
const PARAMS_SIZE = 16;
|
|
39
|
+
const PARAMS_FIELDS_END = 14;
|
|
45
40
|
var BloomParamMismatchError = class extends Error {
|
|
46
41
|
name = "BloomParamMismatchError";
|
|
47
42
|
};
|
|
@@ -56,7 +51,10 @@ var BloomFilter = class BloomFilter {
|
|
|
56
51
|
assertPositiveInt(n, "n");
|
|
57
52
|
assertUint32(n, "n");
|
|
58
53
|
assertProbability(epsilon, "epsilon");
|
|
59
|
-
return BloomFilter
|
|
54
|
+
return new BloomFilter({
|
|
55
|
+
...bloomSizing(n, epsilon),
|
|
56
|
+
n
|
|
57
|
+
});
|
|
60
58
|
}
|
|
61
59
|
static from(keys, epsilon) {
|
|
62
60
|
const arr = [...keys];
|
|
@@ -66,40 +64,41 @@ var BloomFilter = class BloomFilter {
|
|
|
66
64
|
}
|
|
67
65
|
static fromBytes(bytes) {
|
|
68
66
|
const { type, flags, body } = readHeader(bytes);
|
|
69
|
-
if (type !== TYPE) throw new SerializationError(`expected
|
|
67
|
+
if (type !== TYPE) throw new SerializationError(`expected DSTL type ${String(TYPE)}, got ${String(type)}`);
|
|
70
68
|
if ((flags & 15) !== 0) throw new UnknownHashVariantError(`unsupported hash variant ${String(flags & 15)}`);
|
|
71
|
-
assertMinBodyLength(body.length,
|
|
69
|
+
assertMinBodyLength(body.length, PARAMS_SIZE, "bloom");
|
|
70
|
+
assertParamsPadding(body, PARAMS_FIELDS_END, PARAMS_SIZE, "bloom");
|
|
72
71
|
const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
|
|
73
72
|
const m = dv.getUint32(0, true);
|
|
74
73
|
const k = dv.getUint16(4, true);
|
|
75
74
|
const seed = dv.getUint32(6, true);
|
|
76
75
|
const n = dv.getUint32(10, true);
|
|
77
|
-
assertBodyLength(body.length,
|
|
78
|
-
const f = BloomFilter
|
|
76
|
+
assertBodyLength(body.length, PARAMS_SIZE + Math.ceil(m / 8), "bloom");
|
|
77
|
+
const f = new BloomFilter({
|
|
79
78
|
m,
|
|
80
79
|
k,
|
|
81
|
-
seed
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
seed,
|
|
81
|
+
n
|
|
82
|
+
});
|
|
83
|
+
f.#bits.bytes.set(body.subarray(PARAMS_SIZE));
|
|
84
84
|
return f;
|
|
85
85
|
}
|
|
86
|
-
constructor({ m, k, seed = 0 }) {
|
|
86
|
+
constructor({ m, k, seed = 0, n }) {
|
|
87
87
|
assertPositiveInt(m, "m");
|
|
88
88
|
assertUint32(m, "m");
|
|
89
89
|
assertPositiveInt(k, "k");
|
|
90
90
|
assertUint16(k, "k");
|
|
91
91
|
assertUint32(seed, "seed");
|
|
92
|
+
if (n !== void 0) {
|
|
93
|
+
assertPositiveInt(n, "n");
|
|
94
|
+
assertUint32(n, "n");
|
|
95
|
+
}
|
|
92
96
|
this.#bits = new BitSet(m);
|
|
93
97
|
this.#m = m;
|
|
94
98
|
this.#k = k;
|
|
95
99
|
this.#seed = seed;
|
|
96
100
|
this.#scratch = new Uint32Array(k);
|
|
97
|
-
this.#n = Math.round(m * Math.LN2 / k);
|
|
98
|
-
}
|
|
99
|
-
static #withN(params, n) {
|
|
100
|
-
const f = new BloomFilter(params);
|
|
101
|
-
f.#n = n;
|
|
102
|
-
return f;
|
|
101
|
+
this.#n = n ?? Math.max(1, Math.round(m * Math.LN2 / k));
|
|
103
102
|
}
|
|
104
103
|
get m() {
|
|
105
104
|
return this.#m;
|
|
@@ -122,15 +121,15 @@ var BloomFilter = class BloomFilter {
|
|
|
122
121
|
toBytes() {
|
|
123
122
|
const payload = this.#bits.bytes;
|
|
124
123
|
return writeFrame({
|
|
125
|
-
version:
|
|
124
|
+
version: 5,
|
|
126
125
|
type: TYPE,
|
|
127
126
|
flags: 0
|
|
128
|
-
},
|
|
127
|
+
}, PARAMS_SIZE, payload.length, (body, dv) => {
|
|
129
128
|
dv.setUint32(0, this.#m, true);
|
|
130
129
|
dv.setUint16(4, this.#k, true);
|
|
131
130
|
dv.setUint32(6, this.#seed, true);
|
|
132
131
|
dv.setUint32(10, this.#n, true);
|
|
133
|
-
body.set(payload,
|
|
132
|
+
body.set(payload, PARAMS_SIZE);
|
|
134
133
|
});
|
|
135
134
|
}
|
|
136
135
|
equals(other) {
|
|
@@ -148,11 +147,12 @@ var BloomFilter = class BloomFilter {
|
|
|
148
147
|
const b = other.#bits.bytes;
|
|
149
148
|
const merged = new Uint8Array(a.length);
|
|
150
149
|
for (let i = 0; i < a.length; i++) merged[i] = (a[i] ?? 0) | (b[i] ?? 0);
|
|
151
|
-
const r = BloomFilter
|
|
150
|
+
const r = new BloomFilter({
|
|
152
151
|
m: this.#m,
|
|
153
152
|
k: this.#k,
|
|
154
|
-
seed: this.#seed
|
|
155
|
-
|
|
153
|
+
seed: this.#seed,
|
|
154
|
+
n: this.#n
|
|
155
|
+
});
|
|
156
156
|
r.#bits.bytes.set(merged);
|
|
157
157
|
return r;
|
|
158
158
|
}
|
|
@@ -167,4 +167,4 @@ var BloomFilter = class BloomFilter {
|
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
//#endregion
|
|
170
|
-
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,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 };
|
package/dist/fuse/index.cjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
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
|
-
|
|
21
|
+
require_hasher.fmix64(l >>> 0, hi + carry >>> 0);
|
|
20
22
|
}
|
|
21
23
|
function mulhi64(lo, hi, n) {
|
|
22
|
-
|
|
23
|
-
const aLo =
|
|
24
|
-
const aHi =
|
|
25
|
-
|
|
26
|
-
const bHi =
|
|
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) -
|
|
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) -
|
|
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 =
|
|
83
|
-
const mhi =
|
|
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
|
-
|
|
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)}`;
|
|
@@ -159,9 +161,9 @@ function buildState(keys, alloc) {
|
|
|
159
161
|
}
|
|
160
162
|
function fuseStateFromBytes(bytes, expectedType) {
|
|
161
163
|
const { type, flags, body } = require_serialize.readHeader(bytes);
|
|
162
|
-
if (type !== expectedType) throw new require_serialize.SerializationError(`expected
|
|
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,
|
|
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,
|
|
175
|
-
const laneBytes = body.subarray(
|
|
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:
|
|
220
|
-
type
|
|
222
|
+
version: 5,
|
|
223
|
+
type,
|
|
221
224
|
flags: 0
|
|
222
|
-
},
|
|
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,
|
|
230
|
+
body.set(laneBytes, PARAMS_SIZE);
|
|
228
231
|
});
|
|
229
232
|
}
|
|
230
233
|
has(key) {
|
|
231
234
|
if (this.#fp.length === 0) return false;
|
|
232
|
-
|
|
235
|
+
require_hasher.hash128KeyInto(key, 0, scratchHash);
|
|
233
236
|
mixSeed(scratchHash.w0 >>> 0, scratchHash.w1 >>> 0, this.#seed);
|
|
234
|
-
const mlo =
|
|
235
|
-
const mhi =
|
|
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;
|
package/dist/fuse/index.d.cts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
144
|
+
export { BadMagicError, ChecksumError, type FilterJSON, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError };
|
package/dist/fuse/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
144
|
+
export { BadMagicError, ChecksumError, type FilterJSON, ReservedBitsError, SerializationError, TruncatedError, UnknownHashVariantError, UnknownVersionError };
|
package/dist/fuse/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { i as hash128KeyInto, n as RLO, o as mul64, r as fmix64, t as RHI } 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 } 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) -
|
|
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) -
|
|
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 {
|
|
@@ -158,9 +160,9 @@ function buildState(keys, alloc) {
|
|
|
158
160
|
}
|
|
159
161
|
function fuseStateFromBytes(bytes, expectedType) {
|
|
160
162
|
const { type, flags, body } = readHeader(bytes);
|
|
161
|
-
if (type !== expectedType) throw new SerializationError(`expected
|
|
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,
|
|
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,
|
|
174
|
-
const laneBytes = body.subarray(
|
|
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:
|
|
219
|
-
type
|
|
221
|
+
version: 5,
|
|
222
|
+
type,
|
|
220
223
|
flags: 0
|
|
221
|
-
},
|
|
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,
|
|
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 };
|