distillate 0.1.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/LICENSE +21 -0
- package/README.md +105 -0
- package/dist/blocked/index.cjs +116 -0
- package/dist/blocked/index.d.cts +29 -0
- package/dist/blocked/index.d.ts +29 -0
- package/dist/blocked/index.js +114 -0
- package/dist/bloom/index.cjs +132 -0
- package/dist/bloom/index.d.cts +24 -0
- package/dist/bloom/index.d.ts +24 -0
- package/dist/bloom/index.js +130 -0
- package/dist/bytes-DCuYtUVS.d.cts +4 -0
- package/dist/bytes-DCuYtUVS.d.ts +4 -0
- package/dist/fuse/index.cjs +298 -0
- package/dist/fuse/index.d.cts +35 -0
- package/dist/fuse/index.d.ts +35 -0
- package/dist/fuse/index.js +295 -0
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/serialize-C5rwVPvv.cjs +312 -0
- package/dist/serialize-E_4WyueA.js +271 -0
- package/package.json +114 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { a as probeInto, n as readHeader, r as writeHeader } from "../serialize-E_4WyueA.js";
|
|
2
|
+
//#region src/core/bitset.ts
|
|
3
|
+
var BitSetRangeError = class extends RangeError {
|
|
4
|
+
name = "BitSetRangeError";
|
|
5
|
+
};
|
|
6
|
+
const MAX_BITS = 2 ** 32;
|
|
7
|
+
var BitSet = class BitSet {
|
|
8
|
+
#bits;
|
|
9
|
+
static fromBytes(bytes) {
|
|
10
|
+
const bs = new BitSet(bytes.length * 8);
|
|
11
|
+
bs.#bits.set(bytes);
|
|
12
|
+
return bs;
|
|
13
|
+
}
|
|
14
|
+
constructor(nbits) {
|
|
15
|
+
if (nbits > MAX_BITS) throw new BitSetRangeError(`BitSet capacity ${String(nbits)} exceeds the 2^32-bit limit`);
|
|
16
|
+
this.#bits = new Uint8Array(Math.ceil(nbits / 8));
|
|
17
|
+
}
|
|
18
|
+
set(i) {
|
|
19
|
+
const idx = i >>> 3;
|
|
20
|
+
this.#bits[idx] = (this.#bits[idx] ?? 0) | 1 << (i & 7);
|
|
21
|
+
}
|
|
22
|
+
get(i) {
|
|
23
|
+
return ((this.#bits[i >>> 3] ?? 0) & 1 << (i & 7)) !== 0;
|
|
24
|
+
}
|
|
25
|
+
get bytes() {
|
|
26
|
+
return this.#bits;
|
|
27
|
+
}
|
|
28
|
+
count() {
|
|
29
|
+
let total = 0;
|
|
30
|
+
for (let byte of this.#bits) while (byte) {
|
|
31
|
+
byte &= byte - 1;
|
|
32
|
+
total++;
|
|
33
|
+
}
|
|
34
|
+
return total;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/core/sizing.ts
|
|
39
|
+
/** Optimal Bloom-filter sizing: `m` bits and `k` hashes for `n` items at target FPR `epsilon`. */
|
|
40
|
+
function optimal(n, epsilon) {
|
|
41
|
+
const m = Math.ceil(-n * Math.log(epsilon) / (Math.LN2 * Math.LN2));
|
|
42
|
+
return {
|
|
43
|
+
m,
|
|
44
|
+
k: Math.max(1, Math.round(m / n * Math.LN2))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/bloom/bloom.ts
|
|
49
|
+
const TYPE = 1;
|
|
50
|
+
var BloomParamMismatchError = class extends Error {
|
|
51
|
+
name = "BloomParamMismatchError";
|
|
52
|
+
};
|
|
53
|
+
var BloomFilter = class BloomFilter {
|
|
54
|
+
#bits;
|
|
55
|
+
#m;
|
|
56
|
+
#k;
|
|
57
|
+
#seed;
|
|
58
|
+
#scratch;
|
|
59
|
+
#n;
|
|
60
|
+
static create(n, epsilon) {
|
|
61
|
+
const f = new BloomFilter(optimal(n, epsilon));
|
|
62
|
+
f.#n = n;
|
|
63
|
+
return f;
|
|
64
|
+
}
|
|
65
|
+
static fromBytes(bytes) {
|
|
66
|
+
const { body } = readHeader(bytes);
|
|
67
|
+
const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
|
|
68
|
+
const m = dv.getUint32(0, true);
|
|
69
|
+
const k = body[4] ?? 0;
|
|
70
|
+
const seed = dv.getUint32(5, true);
|
|
71
|
+
const f = new BloomFilter({
|
|
72
|
+
m,
|
|
73
|
+
k,
|
|
74
|
+
seed
|
|
75
|
+
});
|
|
76
|
+
f.#bits.bytes.set(body.subarray(9));
|
|
77
|
+
return f;
|
|
78
|
+
}
|
|
79
|
+
constructor({ m, k, seed = 0 }) {
|
|
80
|
+
this.#bits = new BitSet(m);
|
|
81
|
+
this.#m = m;
|
|
82
|
+
this.#k = k;
|
|
83
|
+
this.#seed = seed;
|
|
84
|
+
this.#scratch = new Uint32Array(k);
|
|
85
|
+
this.#n = Math.round(m * Math.LN2 / k);
|
|
86
|
+
}
|
|
87
|
+
/** Analytic design bits-per-key `m / n`. */
|
|
88
|
+
get bitsPerKey() {
|
|
89
|
+
return this.#m / this.#n;
|
|
90
|
+
}
|
|
91
|
+
toBytes() {
|
|
92
|
+
const payload = this.#bits.bytes;
|
|
93
|
+
const body = new Uint8Array(9 + payload.length);
|
|
94
|
+
const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
|
|
95
|
+
dv.setUint32(0, this.#m, true);
|
|
96
|
+
body[4] = this.#k;
|
|
97
|
+
dv.setUint32(5, this.#seed, true);
|
|
98
|
+
body.set(payload, 9);
|
|
99
|
+
return writeHeader({
|
|
100
|
+
version: 1,
|
|
101
|
+
type: TYPE,
|
|
102
|
+
flags: 0
|
|
103
|
+
}, body);
|
|
104
|
+
}
|
|
105
|
+
union(other) {
|
|
106
|
+
if (this.#m !== other.#m || this.#k !== other.#k || this.#seed !== other.#seed) throw new BloomParamMismatchError("cannot union Bloom filters whose parameters do not match");
|
|
107
|
+
const a = this.#bits.bytes;
|
|
108
|
+
const b = other.#bits.bytes;
|
|
109
|
+
const merged = new Uint8Array(a.length);
|
|
110
|
+
for (let i = 0; i < a.length; i++) merged[i] = (a[i] ?? 0) | (b[i] ?? 0);
|
|
111
|
+
const r = new BloomFilter({
|
|
112
|
+
m: this.#m,
|
|
113
|
+
k: this.#k,
|
|
114
|
+
seed: this.#seed
|
|
115
|
+
});
|
|
116
|
+
r.#bits.bytes.set(merged);
|
|
117
|
+
return r;
|
|
118
|
+
}
|
|
119
|
+
add(key) {
|
|
120
|
+
probeInto(key, this.#k, this.#m, this.#seed, this.#scratch);
|
|
121
|
+
for (let i = 0; i < this.#k; i++) this.#bits.set(this.#scratch[i] ?? 0);
|
|
122
|
+
}
|
|
123
|
+
has(key) {
|
|
124
|
+
probeInto(key, this.#k, this.#m, this.#seed, this.#scratch);
|
|
125
|
+
for (let i = 0; i < this.#k; i++) if (!this.#bits.get(this.#scratch[i] ?? 0)) return false;
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
//#endregion
|
|
130
|
+
export { BloomFilter, BloomParamMismatchError };
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_serialize = require("../serialize-C5rwVPvv.cjs");
|
|
3
|
+
//#region src/fuse/fuse.ts
|
|
4
|
+
const ARITY = 3;
|
|
5
|
+
const TYPE_FUSE8 = 3;
|
|
6
|
+
const TYPE_FUSE16 = 4;
|
|
7
|
+
var BinaryFuseBuildError = class extends Error {
|
|
8
|
+
name = "BinaryFuseBuildError";
|
|
9
|
+
};
|
|
10
|
+
let RLO = 0;
|
|
11
|
+
let RHI = 0;
|
|
12
|
+
function mul64(alo, ahi, blo, bhi) {
|
|
13
|
+
const a0 = alo & 65535;
|
|
14
|
+
const a1 = alo >>> 16;
|
|
15
|
+
const a2 = ahi & 65535;
|
|
16
|
+
const a3 = ahi >>> 16;
|
|
17
|
+
const b0 = blo & 65535;
|
|
18
|
+
const b1 = blo >>> 16;
|
|
19
|
+
const b2 = bhi & 65535;
|
|
20
|
+
const b3 = bhi >>> 16;
|
|
21
|
+
let c0 = a0 * b0;
|
|
22
|
+
let c1 = c0 >>> 16;
|
|
23
|
+
c0 &= 65535;
|
|
24
|
+
c1 += a1 * b0;
|
|
25
|
+
let c2 = c1 >>> 16;
|
|
26
|
+
c1 &= 65535;
|
|
27
|
+
c1 += a0 * b1;
|
|
28
|
+
c2 += c1 >>> 16;
|
|
29
|
+
c1 &= 65535;
|
|
30
|
+
c2 += a2 * b0;
|
|
31
|
+
let c3 = c2 >>> 16;
|
|
32
|
+
c2 &= 65535;
|
|
33
|
+
c2 += a1 * b1;
|
|
34
|
+
c3 += c2 >>> 16;
|
|
35
|
+
c2 &= 65535;
|
|
36
|
+
c2 += a0 * b2;
|
|
37
|
+
c3 += c2 >>> 16;
|
|
38
|
+
c2 &= 65535;
|
|
39
|
+
c3 += a3 * b0 + a2 * b1 + a1 * b2 + a0 * b3;
|
|
40
|
+
c3 &= 65535;
|
|
41
|
+
RLO = (c1 << 16 | c0) >>> 0;
|
|
42
|
+
RHI = (c3 << 16 | c2) >>> 0;
|
|
43
|
+
}
|
|
44
|
+
function fmix64(lo, hi) {
|
|
45
|
+
let l = (lo ^ hi >>> 1) >>> 0;
|
|
46
|
+
let h = hi;
|
|
47
|
+
mul64(l, h, 3981806797, 4283543511);
|
|
48
|
+
l = RLO;
|
|
49
|
+
h = RHI;
|
|
50
|
+
l = (l ^ h >>> 1) >>> 0;
|
|
51
|
+
mul64(l, h, 444984403, 3301882366);
|
|
52
|
+
l = RLO;
|
|
53
|
+
h = RHI;
|
|
54
|
+
l = (l ^ h >>> 1) >>> 0;
|
|
55
|
+
RLO = l;
|
|
56
|
+
RHI = h;
|
|
57
|
+
}
|
|
58
|
+
function mixSeed(lo, hi, seed) {
|
|
59
|
+
const l = (lo >>> 0) + (seed >>> 0);
|
|
60
|
+
const carry = l > 4294967295 ? 1 : 0;
|
|
61
|
+
fmix64(l >>> 0, hi + carry >>> 0);
|
|
62
|
+
}
|
|
63
|
+
function mulhi64(lo, hi, n) {
|
|
64
|
+
mul64(hi, 0, n, 0);
|
|
65
|
+
const aLo = RLO;
|
|
66
|
+
const aHi = RHI;
|
|
67
|
+
mul64(lo, 0, n, 0);
|
|
68
|
+
const bHi = RHI;
|
|
69
|
+
return aHi + ((aLo >>> 0) + (bHi >>> 0) > 4294967295 ? 1 : 0) >>> 0;
|
|
70
|
+
}
|
|
71
|
+
function positionsInto(mlo, mhi, seg, segMask, segCountLen, out) {
|
|
72
|
+
const h0 = mulhi64(mlo, mhi, segCountLen);
|
|
73
|
+
let h1 = h0 + seg >>> 0;
|
|
74
|
+
let h2 = h1 + seg >>> 0;
|
|
75
|
+
h1 = (h1 ^ (mlo >>> 18 | mhi << 14) & segMask) >>> 0;
|
|
76
|
+
h2 = (h2 ^ mlo & segMask) >>> 0;
|
|
77
|
+
out[0] = h0;
|
|
78
|
+
out[1] = h1;
|
|
79
|
+
out[2] = h2;
|
|
80
|
+
}
|
|
81
|
+
function fpMask(fp) {
|
|
82
|
+
return (1 << 8 * fp.BYTES_PER_ELEMENT) - 1 >>> 0;
|
|
83
|
+
}
|
|
84
|
+
function computeParams(size) {
|
|
85
|
+
const seg = Math.min(1 << Math.floor(Math.log(size) / Math.log(3.33) + 2.25), 1 << 18);
|
|
86
|
+
const segMask = seg - 1;
|
|
87
|
+
const sizeFactor = Math.max(1.125, .875 + .25 * Math.log(1e6) / Math.log(Math.max(size, 2)));
|
|
88
|
+
const capacity = Math.round(size * sizeFactor);
|
|
89
|
+
let segCount = Math.floor((capacity + seg - 1) / seg) - (ARITY - 1);
|
|
90
|
+
if (segCount <= 0) segCount = 1;
|
|
91
|
+
let arrayLength = (segCount + ARITY - 1) * seg;
|
|
92
|
+
segCount = Math.floor((arrayLength + seg - 1) / seg) - (ARITY - 1);
|
|
93
|
+
if (segCount <= 0) segCount = 1;
|
|
94
|
+
arrayLength = (segCount + ARITY - 1) * seg;
|
|
95
|
+
return {
|
|
96
|
+
seg,
|
|
97
|
+
segMask,
|
|
98
|
+
segCountLen: segCount * seg,
|
|
99
|
+
arrayLength
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Peel the 3-hypergraph and assign fingerprints so every key's XOR of its 3
|
|
104
|
+
* lanes equals its fingerprint. Retries with a bumped seed on a stall; returns
|
|
105
|
+
* the seed that succeeded.
|
|
106
|
+
*/
|
|
107
|
+
function buildFingerprints(fp, hashes, params, maxAttempts = 100) {
|
|
108
|
+
const size = hashes.length / 2;
|
|
109
|
+
const { seg, segMask, segCountLen, arrayLength } = params;
|
|
110
|
+
const mask = fpMask(fp);
|
|
111
|
+
const counts = new Uint32Array(arrayLength);
|
|
112
|
+
const xorLo = new Uint32Array(arrayLength);
|
|
113
|
+
const xorHi = new Uint32Array(arrayLength);
|
|
114
|
+
const orderLo = new Uint32Array(size);
|
|
115
|
+
const orderHi = new Uint32Array(size);
|
|
116
|
+
const orderIdx = new Uint32Array(size);
|
|
117
|
+
const pos = /* @__PURE__ */ new Uint32Array(3);
|
|
118
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
119
|
+
const seed = attempt;
|
|
120
|
+
counts.fill(0);
|
|
121
|
+
xorLo.fill(0);
|
|
122
|
+
xorHi.fill(0);
|
|
123
|
+
for (let i = 0; i < size; i++) {
|
|
124
|
+
mixSeed(hashes[2 * i] ?? 0, hashes[2 * i + 1] ?? 0, seed);
|
|
125
|
+
const mlo = RLO;
|
|
126
|
+
const mhi = RHI;
|
|
127
|
+
positionsInto(mlo, mhi, seg, segMask, segCountLen, pos);
|
|
128
|
+
for (let j = 0; j < 3; j++) {
|
|
129
|
+
const p = pos[j] ?? 0;
|
|
130
|
+
counts[p] = (counts[p] ?? 0) + 1;
|
|
131
|
+
xorLo[p] = (xorLo[p] ?? 0) ^ mlo;
|
|
132
|
+
xorHi[p] = (xorHi[p] ?? 0) ^ mhi;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const queue = [];
|
|
136
|
+
for (let idx = 0; idx < arrayLength; idx++) if ((counts[idx] ?? 0) === 1) queue.push(idx);
|
|
137
|
+
let processed = 0;
|
|
138
|
+
while (queue.length > 0) {
|
|
139
|
+
const idx = queue.pop();
|
|
140
|
+
if (idx === void 0) break;
|
|
141
|
+
if ((counts[idx] ?? 0) !== 1) continue;
|
|
142
|
+
const mlo = xorLo[idx] ?? 0;
|
|
143
|
+
const mhi = xorHi[idx] ?? 0;
|
|
144
|
+
orderLo[processed] = mlo;
|
|
145
|
+
orderHi[processed] = mhi;
|
|
146
|
+
orderIdx[processed] = idx;
|
|
147
|
+
processed++;
|
|
148
|
+
positionsInto(mlo, mhi, seg, segMask, segCountLen, pos);
|
|
149
|
+
for (let j = 0; j < 3; j++) {
|
|
150
|
+
const p = pos[j] ?? 0;
|
|
151
|
+
counts[p] = (counts[p] ?? 0) - 1;
|
|
152
|
+
xorLo[p] = (xorLo[p] ?? 0) ^ mlo;
|
|
153
|
+
xorHi[p] = (xorHi[p] ?? 0) ^ mhi;
|
|
154
|
+
if ((counts[p] ?? 0) === 1) queue.push(p);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (processed === size) {
|
|
158
|
+
fp.fill(0);
|
|
159
|
+
for (let i = processed - 1; i >= 0; i--) {
|
|
160
|
+
const mlo = orderLo[i] ?? 0;
|
|
161
|
+
const mhi = orderHi[i] ?? 0;
|
|
162
|
+
const idx = orderIdx[i] ?? 0;
|
|
163
|
+
positionsInto(mlo, mhi, seg, segMask, segCountLen, pos);
|
|
164
|
+
const p0 = pos[0] ?? 0;
|
|
165
|
+
const p1 = pos[1] ?? 0;
|
|
166
|
+
const p2 = pos[2] ?? 0;
|
|
167
|
+
fp[idx] = ((mlo ^ mhi) & mask ^ (fp[p0] ?? 0) ^ (fp[p1] ?? 0) ^ (fp[p2] ?? 0)) & mask;
|
|
168
|
+
}
|
|
169
|
+
return seed;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
throw new BinaryFuseBuildError("binary fuse construction failed");
|
|
173
|
+
}
|
|
174
|
+
function buildState(keys, alloc) {
|
|
175
|
+
const hashList = [];
|
|
176
|
+
const seen = /* @__PURE__ */ new Set();
|
|
177
|
+
for (const key of keys) {
|
|
178
|
+
const { h1lo, h1hi } = require_serialize.hash128(require_serialize.normalize(key), 0);
|
|
179
|
+
const lo = h1lo >>> 0;
|
|
180
|
+
const hi = h1hi >>> 0;
|
|
181
|
+
const id = `${String(lo)},${String(hi)}`;
|
|
182
|
+
if (seen.has(id)) continue;
|
|
183
|
+
seen.add(id);
|
|
184
|
+
hashList.push(lo, hi);
|
|
185
|
+
}
|
|
186
|
+
const size = hashList.length / 2;
|
|
187
|
+
const params = computeParams(size);
|
|
188
|
+
if (size === 0) return {
|
|
189
|
+
fp: alloc(0),
|
|
190
|
+
seed: 0,
|
|
191
|
+
params,
|
|
192
|
+
size: 0
|
|
193
|
+
};
|
|
194
|
+
const hashes = Uint32Array.from(hashList);
|
|
195
|
+
const fp = alloc(params.arrayLength);
|
|
196
|
+
return {
|
|
197
|
+
fp,
|
|
198
|
+
seed: buildFingerprints(fp, hashes, params),
|
|
199
|
+
params,
|
|
200
|
+
size
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function fuseStateFromBytes(bytes, expectedType) {
|
|
204
|
+
const { type, body } = require_serialize.readHeader(bytes);
|
|
205
|
+
if (type !== expectedType) throw new require_serialize.SerializationError(`expected AMQF type ${String(expectedType)}, got ${String(type)}`);
|
|
206
|
+
const dv = new DataView(body.buffer, body.byteOffset, body.byteLength);
|
|
207
|
+
const seed = dv.getUint32(0, true);
|
|
208
|
+
const seg = dv.getUint32(4, true);
|
|
209
|
+
const segCountLen = dv.getUint32(8, true);
|
|
210
|
+
const size = dv.getUint32(12, true);
|
|
211
|
+
const laneBytes = body.subarray(16);
|
|
212
|
+
const bpe = expectedType === TYPE_FUSE8 ? 1 : 2;
|
|
213
|
+
const arrayLength = laneBytes.length / bpe;
|
|
214
|
+
const fp = bpe === 1 ? new Uint8Array(arrayLength) : new Uint16Array(arrayLength);
|
|
215
|
+
new Uint8Array(fp.buffer).set(laneBytes);
|
|
216
|
+
return {
|
|
217
|
+
fp,
|
|
218
|
+
seed,
|
|
219
|
+
params: {
|
|
220
|
+
seg,
|
|
221
|
+
segMask: seg - 1,
|
|
222
|
+
segCountLen,
|
|
223
|
+
arrayLength
|
|
224
|
+
},
|
|
225
|
+
size
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
var BinaryFuse = class {
|
|
229
|
+
#fp;
|
|
230
|
+
#seed;
|
|
231
|
+
#seg;
|
|
232
|
+
#segMask;
|
|
233
|
+
#segCountLen;
|
|
234
|
+
#size;
|
|
235
|
+
#pos = /* @__PURE__ */ new Uint32Array(3);
|
|
236
|
+
constructor(state) {
|
|
237
|
+
this.#fp = state.fp;
|
|
238
|
+
this.#seed = state.seed;
|
|
239
|
+
this.#seg = state.params.seg;
|
|
240
|
+
this.#segMask = state.params.segMask;
|
|
241
|
+
this.#segCountLen = state.params.segCountLen;
|
|
242
|
+
this.#size = state.size;
|
|
243
|
+
}
|
|
244
|
+
get size() {
|
|
245
|
+
return this.#size;
|
|
246
|
+
}
|
|
247
|
+
get bitsPerKey() {
|
|
248
|
+
return this.#size === 0 ? 0 : this.#fp.byteLength * 8 / this.#size;
|
|
249
|
+
}
|
|
250
|
+
toBytes() {
|
|
251
|
+
const laneBytes = new Uint8Array(this.#fp.buffer, this.#fp.byteOffset, this.#fp.byteLength);
|
|
252
|
+
const body = new Uint8Array(16 + laneBytes.length);
|
|
253
|
+
const dv = new DataView(body.buffer);
|
|
254
|
+
dv.setUint32(0, this.#seed, true);
|
|
255
|
+
dv.setUint32(4, this.#seg, true);
|
|
256
|
+
dv.setUint32(8, this.#segCountLen, true);
|
|
257
|
+
dv.setUint32(12, this.#size, true);
|
|
258
|
+
body.set(laneBytes, 16);
|
|
259
|
+
return require_serialize.writeHeader({
|
|
260
|
+
version: 1,
|
|
261
|
+
type: this.#fp.BYTES_PER_ELEMENT === 1 ? TYPE_FUSE8 : TYPE_FUSE16,
|
|
262
|
+
flags: 0
|
|
263
|
+
}, body);
|
|
264
|
+
}
|
|
265
|
+
has(key) {
|
|
266
|
+
if (this.#fp.length === 0) return false;
|
|
267
|
+
const { h1lo, h1hi } = require_serialize.hash128(require_serialize.normalize(key), 0);
|
|
268
|
+
mixSeed(h1lo >>> 0, h1hi >>> 0, this.#seed);
|
|
269
|
+
const mlo = RLO;
|
|
270
|
+
const mhi = RHI;
|
|
271
|
+
positionsInto(mlo, mhi, this.#seg, this.#segMask, this.#segCountLen, this.#pos);
|
|
272
|
+
const mask = fpMask(this.#fp);
|
|
273
|
+
const p0 = this.#pos[0] ?? 0;
|
|
274
|
+
const p1 = this.#pos[1] ?? 0;
|
|
275
|
+
const p2 = this.#pos[2] ?? 0;
|
|
276
|
+
return ((mlo ^ mhi) & mask) === (((this.#fp[p0] ?? 0) ^ (this.#fp[p1] ?? 0) ^ (this.#fp[p2] ?? 0)) & mask);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
var BinaryFuse8 = class BinaryFuse8 extends BinaryFuse {
|
|
280
|
+
static from(keys) {
|
|
281
|
+
return new BinaryFuse8(buildState(keys, (n) => new Uint8Array(n)));
|
|
282
|
+
}
|
|
283
|
+
static fromBytes(bytes) {
|
|
284
|
+
return new BinaryFuse8(fuseStateFromBytes(bytes, TYPE_FUSE8));
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var BinaryFuse16 = class BinaryFuse16 extends BinaryFuse {
|
|
288
|
+
static from(keys) {
|
|
289
|
+
return new BinaryFuse16(buildState(keys, (n) => new Uint16Array(n)));
|
|
290
|
+
}
|
|
291
|
+
static fromBytes(bytes) {
|
|
292
|
+
return new BinaryFuse16(fuseStateFromBytes(bytes, TYPE_FUSE16));
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
//#endregion
|
|
296
|
+
exports.BinaryFuse16 = BinaryFuse16;
|
|
297
|
+
exports.BinaryFuse8 = BinaryFuse8;
|
|
298
|
+
exports.BinaryFuseBuildError = BinaryFuseBuildError;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { t as BytesLike } from "../bytes-DCuYtUVS.cjs";
|
|
2
|
+
//#region src/fuse/fuse.d.ts
|
|
3
|
+
declare class BinaryFuseBuildError extends Error {
|
|
4
|
+
override readonly name = "BinaryFuseBuildError";
|
|
5
|
+
}
|
|
6
|
+
interface FuseParams {
|
|
7
|
+
seg: number;
|
|
8
|
+
segMask: number;
|
|
9
|
+
segCountLen: number;
|
|
10
|
+
arrayLength: number;
|
|
11
|
+
}
|
|
12
|
+
interface FuseState {
|
|
13
|
+
fp: Uint8Array | Uint16Array;
|
|
14
|
+
seed: number;
|
|
15
|
+
params: FuseParams;
|
|
16
|
+
size: number;
|
|
17
|
+
}
|
|
18
|
+
declare abstract class BinaryFuse {
|
|
19
|
+
#private;
|
|
20
|
+
protected constructor(state: FuseState);
|
|
21
|
+
get size(): number;
|
|
22
|
+
get bitsPerKey(): number;
|
|
23
|
+
toBytes(): Uint8Array;
|
|
24
|
+
has(key: BytesLike): boolean;
|
|
25
|
+
}
|
|
26
|
+
declare class BinaryFuse8 extends BinaryFuse {
|
|
27
|
+
static from(keys: Iterable<BytesLike>): BinaryFuse8;
|
|
28
|
+
static fromBytes(bytes: Uint8Array): BinaryFuse8;
|
|
29
|
+
}
|
|
30
|
+
declare class BinaryFuse16 extends BinaryFuse {
|
|
31
|
+
static from(keys: Iterable<BytesLike>): BinaryFuse16;
|
|
32
|
+
static fromBytes(bytes: Uint8Array): BinaryFuse16;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { BinaryFuse16, BinaryFuse8, BinaryFuseBuildError };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { t as BytesLike } from "../bytes-DCuYtUVS.js";
|
|
2
|
+
//#region src/fuse/fuse.d.ts
|
|
3
|
+
declare class BinaryFuseBuildError extends Error {
|
|
4
|
+
override readonly name = "BinaryFuseBuildError";
|
|
5
|
+
}
|
|
6
|
+
interface FuseParams {
|
|
7
|
+
seg: number;
|
|
8
|
+
segMask: number;
|
|
9
|
+
segCountLen: number;
|
|
10
|
+
arrayLength: number;
|
|
11
|
+
}
|
|
12
|
+
interface FuseState {
|
|
13
|
+
fp: Uint8Array | Uint16Array;
|
|
14
|
+
seed: number;
|
|
15
|
+
params: FuseParams;
|
|
16
|
+
size: number;
|
|
17
|
+
}
|
|
18
|
+
declare abstract class BinaryFuse {
|
|
19
|
+
#private;
|
|
20
|
+
protected constructor(state: FuseState);
|
|
21
|
+
get size(): number;
|
|
22
|
+
get bitsPerKey(): number;
|
|
23
|
+
toBytes(): Uint8Array;
|
|
24
|
+
has(key: BytesLike): boolean;
|
|
25
|
+
}
|
|
26
|
+
declare class BinaryFuse8 extends BinaryFuse {
|
|
27
|
+
static from(keys: Iterable<BytesLike>): BinaryFuse8;
|
|
28
|
+
static fromBytes(bytes: Uint8Array): BinaryFuse8;
|
|
29
|
+
}
|
|
30
|
+
declare class BinaryFuse16 extends BinaryFuse {
|
|
31
|
+
static from(keys: Iterable<BytesLike>): BinaryFuse16;
|
|
32
|
+
static fromBytes(bytes: Uint8Array): BinaryFuse16;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { BinaryFuse16, BinaryFuse8, BinaryFuseBuildError };
|