distillate 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocked/index.cjs +10 -4
- package/dist/blocked/index.js +10 -4
- package/dist/bloom/index.cjs +1 -1
- package/dist/bloom/index.js +1 -1
- package/dist/fuse/index.cjs +12 -6
- package/dist/fuse/index.js +12 -6
- package/dist/{serialize-E_4WyueA.js → serialize-5XQ5y_R-.js} +35 -12
- package/dist/{serialize-C5rwVPvv.cjs → serialize-CHHDM4TQ.cjs} +36 -19
- package/package.json +19 -20
package/dist/blocked/index.cjs
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_serialize = require("../serialize-
|
|
2
|
+
const require_serialize = require("../serialize-CHHDM4TQ.cjs");
|
|
3
3
|
//#region src/blocked/blocked.ts
|
|
4
4
|
const TYPE = 2;
|
|
5
5
|
const SALT = Uint32Array.of(1203114875, 1150766481, 2284105051, 2729912477, 1884591559, 770785867, 2667333959, 1550580529);
|
|
6
|
+
const scratchHash = {
|
|
7
|
+
h1lo: 0,
|
|
8
|
+
h1hi: 0,
|
|
9
|
+
h2lo: 0,
|
|
10
|
+
h2hi: 0
|
|
11
|
+
};
|
|
6
12
|
/**
|
|
7
13
|
* Split-block probe: derive one block index and 8 single-bit lane masks for
|
|
8
14
|
* `key`. Writes lane word indices into `outWords` and their masks into
|
|
@@ -102,9 +108,9 @@ var BlockedBloomFilter = class BlockedBloomFilter {
|
|
|
102
108
|
}
|
|
103
109
|
};
|
|
104
110
|
function fillBlock(key, numBlocks, seed, outWords, outBits) {
|
|
105
|
-
|
|
106
|
-
const block = require_serialize.reduce((h1lo ^ h1hi) >>> 0, numBlocks);
|
|
107
|
-
const x = (h2lo ^ h2hi) >>> 0;
|
|
111
|
+
require_serialize.hash128KeyInto(key, seed, scratchHash);
|
|
112
|
+
const block = require_serialize.reduce((scratchHash.h1lo ^ scratchHash.h1hi) >>> 0, numBlocks);
|
|
113
|
+
const x = (scratchHash.h2lo ^ scratchHash.h2hi) >>> 0;
|
|
108
114
|
const base = block * 8;
|
|
109
115
|
for (let i = 0; i < 8; i++) {
|
|
110
116
|
outWords[i] = base + i;
|
package/dist/blocked/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { i as hash128KeyInto, n as readHeader, o as reduce, r as writeHeader } from "../serialize-5XQ5y_R-.js";
|
|
2
2
|
//#region src/blocked/blocked.ts
|
|
3
3
|
const TYPE = 2;
|
|
4
4
|
const SALT = Uint32Array.of(1203114875, 1150766481, 2284105051, 2729912477, 1884591559, 770785867, 2667333959, 1550580529);
|
|
5
|
+
const scratchHash = {
|
|
6
|
+
h1lo: 0,
|
|
7
|
+
h1hi: 0,
|
|
8
|
+
h2lo: 0,
|
|
9
|
+
h2hi: 0
|
|
10
|
+
};
|
|
5
11
|
/**
|
|
6
12
|
* Split-block probe: derive one block index and 8 single-bit lane masks for
|
|
7
13
|
* `key`. Writes lane word indices into `outWords` and their masks into
|
|
@@ -101,9 +107,9 @@ var BlockedBloomFilter = class BlockedBloomFilter {
|
|
|
101
107
|
}
|
|
102
108
|
};
|
|
103
109
|
function fillBlock(key, numBlocks, seed, outWords, outBits) {
|
|
104
|
-
|
|
105
|
-
const block = reduce((h1lo ^ h1hi) >>> 0, numBlocks);
|
|
106
|
-
const x = (h2lo ^ h2hi) >>> 0;
|
|
110
|
+
hash128KeyInto(key, seed, scratchHash);
|
|
111
|
+
const block = reduce((scratchHash.h1lo ^ scratchHash.h1hi) >>> 0, numBlocks);
|
|
112
|
+
const x = (scratchHash.h2lo ^ scratchHash.h2hi) >>> 0;
|
|
107
113
|
const base = block * 8;
|
|
108
114
|
for (let i = 0; i < 8; i++) {
|
|
109
115
|
outWords[i] = base + i;
|
package/dist/bloom/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_serialize = require("../serialize-
|
|
2
|
+
const require_serialize = require("../serialize-CHHDM4TQ.cjs");
|
|
3
3
|
//#region src/core/bitset.ts
|
|
4
4
|
var BitSetRangeError = class extends RangeError {
|
|
5
5
|
name = "BitSetRangeError";
|
package/dist/bloom/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as probeInto, n as readHeader, r as writeHeader } from "../serialize-
|
|
1
|
+
import { a as probeInto, n as readHeader, r as writeHeader } from "../serialize-5XQ5y_R-.js";
|
|
2
2
|
//#region src/core/bitset.ts
|
|
3
3
|
var BitSetRangeError = class extends RangeError {
|
|
4
4
|
name = "BitSetRangeError";
|
package/dist/fuse/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_serialize = require("../serialize-
|
|
2
|
+
const require_serialize = require("../serialize-CHHDM4TQ.cjs");
|
|
3
3
|
//#region src/fuse/fuse.ts
|
|
4
4
|
const ARITY = 3;
|
|
5
5
|
const TYPE_FUSE8 = 3;
|
|
@@ -9,6 +9,12 @@ var BinaryFuseBuildError = class extends Error {
|
|
|
9
9
|
};
|
|
10
10
|
let RLO = 0;
|
|
11
11
|
let RHI = 0;
|
|
12
|
+
const scratchHash = {
|
|
13
|
+
h1lo: 0,
|
|
14
|
+
h1hi: 0,
|
|
15
|
+
h2lo: 0,
|
|
16
|
+
h2hi: 0
|
|
17
|
+
};
|
|
12
18
|
function mul64(alo, ahi, blo, bhi) {
|
|
13
19
|
const a0 = alo & 65535;
|
|
14
20
|
const a1 = alo >>> 16;
|
|
@@ -175,9 +181,9 @@ function buildState(keys, alloc) {
|
|
|
175
181
|
const hashList = [];
|
|
176
182
|
const seen = /* @__PURE__ */ new Set();
|
|
177
183
|
for (const key of keys) {
|
|
178
|
-
|
|
179
|
-
const lo = h1lo >>> 0;
|
|
180
|
-
const hi = h1hi >>> 0;
|
|
184
|
+
require_serialize.hash128KeyInto(key, 0, scratchHash);
|
|
185
|
+
const lo = scratchHash.h1lo >>> 0;
|
|
186
|
+
const hi = scratchHash.h1hi >>> 0;
|
|
181
187
|
const id = `${String(lo)},${String(hi)}`;
|
|
182
188
|
if (seen.has(id)) continue;
|
|
183
189
|
seen.add(id);
|
|
@@ -264,8 +270,8 @@ var BinaryFuse = class {
|
|
|
264
270
|
}
|
|
265
271
|
has(key) {
|
|
266
272
|
if (this.#fp.length === 0) return false;
|
|
267
|
-
|
|
268
|
-
mixSeed(h1lo >>> 0, h1hi >>> 0, this.#seed);
|
|
273
|
+
require_serialize.hash128KeyInto(key, 0, scratchHash);
|
|
274
|
+
mixSeed(scratchHash.h1lo >>> 0, scratchHash.h1hi >>> 0, this.#seed);
|
|
269
275
|
const mlo = RLO;
|
|
270
276
|
const mhi = RHI;
|
|
271
277
|
positionsInto(mlo, mhi, this.#seg, this.#segMask, this.#segCountLen, this.#pos);
|
package/dist/fuse/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { i as hash128KeyInto, n as readHeader, r as writeHeader, t as SerializationError } from "../serialize-5XQ5y_R-.js";
|
|
2
2
|
//#region src/fuse/fuse.ts
|
|
3
3
|
const ARITY = 3;
|
|
4
4
|
const TYPE_FUSE8 = 3;
|
|
@@ -8,6 +8,12 @@ var BinaryFuseBuildError = class extends Error {
|
|
|
8
8
|
};
|
|
9
9
|
let RLO = 0;
|
|
10
10
|
let RHI = 0;
|
|
11
|
+
const scratchHash = {
|
|
12
|
+
h1lo: 0,
|
|
13
|
+
h1hi: 0,
|
|
14
|
+
h2lo: 0,
|
|
15
|
+
h2hi: 0
|
|
16
|
+
};
|
|
11
17
|
function mul64(alo, ahi, blo, bhi) {
|
|
12
18
|
const a0 = alo & 65535;
|
|
13
19
|
const a1 = alo >>> 16;
|
|
@@ -174,9 +180,9 @@ function buildState(keys, alloc) {
|
|
|
174
180
|
const hashList = [];
|
|
175
181
|
const seen = /* @__PURE__ */ new Set();
|
|
176
182
|
for (const key of keys) {
|
|
177
|
-
|
|
178
|
-
const lo = h1lo >>> 0;
|
|
179
|
-
const hi = h1hi >>> 0;
|
|
183
|
+
hash128KeyInto(key, 0, scratchHash);
|
|
184
|
+
const lo = scratchHash.h1lo >>> 0;
|
|
185
|
+
const hi = scratchHash.h1hi >>> 0;
|
|
180
186
|
const id = `${String(lo)},${String(hi)}`;
|
|
181
187
|
if (seen.has(id)) continue;
|
|
182
188
|
seen.add(id);
|
|
@@ -263,8 +269,8 @@ var BinaryFuse = class {
|
|
|
263
269
|
}
|
|
264
270
|
has(key) {
|
|
265
271
|
if (this.#fp.length === 0) return false;
|
|
266
|
-
|
|
267
|
-
mixSeed(h1lo >>> 0, h1hi >>> 0, this.#seed);
|
|
272
|
+
hash128KeyInto(key, 0, scratchHash);
|
|
273
|
+
mixSeed(scratchHash.h1lo >>> 0, scratchHash.h1hi >>> 0, this.#seed);
|
|
268
274
|
const mlo = RLO;
|
|
269
275
|
const mhi = RHI;
|
|
270
276
|
positionsInto(mlo, mhi, this.#seg, this.#segMask, this.#segCountLen, this.#pos);
|
|
@@ -13,6 +13,12 @@ const C2LO = 658871167;
|
|
|
13
13
|
const C2HI = 1291169091;
|
|
14
14
|
let RLO = 0;
|
|
15
15
|
let RHI = 0;
|
|
16
|
+
const LANES = {
|
|
17
|
+
h1lo: 0,
|
|
18
|
+
h1hi: 0,
|
|
19
|
+
h2lo: 0,
|
|
20
|
+
h2hi: 0
|
|
21
|
+
};
|
|
16
22
|
function mul64(alo, ahi, blo, bhi) {
|
|
17
23
|
const a0 = alo & 65535;
|
|
18
24
|
const a1 = alo >>> 16;
|
|
@@ -75,8 +81,7 @@ function fmix64(lo, hi) {
|
|
|
75
81
|
RLO = l;
|
|
76
82
|
RHI = h;
|
|
77
83
|
}
|
|
78
|
-
function
|
|
79
|
-
const len = bytes.length;
|
|
84
|
+
function computeLanes(bytes, seed, len) {
|
|
80
85
|
const nblocks = len >>> 4;
|
|
81
86
|
let h1lo = seed >>> 0;
|
|
82
87
|
let h1hi = 0;
|
|
@@ -174,12 +179,30 @@ function hash128(bytes, seed = 0) {
|
|
|
174
179
|
add64(h2lo, h2hi, h1lo, h1hi);
|
|
175
180
|
h2lo = RLO;
|
|
176
181
|
h2hi = RHI;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
LANES.h1lo = h1lo >>> 0;
|
|
183
|
+
LANES.h1hi = h1hi >>> 0;
|
|
184
|
+
LANES.h2lo = h2lo >>> 0;
|
|
185
|
+
LANES.h2hi = h2hi >>> 0;
|
|
186
|
+
}
|
|
187
|
+
const keyEncoder = new TextEncoder();
|
|
188
|
+
let keyBuf = /* @__PURE__ */ new Uint8Array(256);
|
|
189
|
+
function keyToLanes(key, seed) {
|
|
190
|
+
if (typeof key === "string") {
|
|
191
|
+
const cap = key.length * 3;
|
|
192
|
+
if (keyBuf.length < cap) keyBuf = new Uint8Array(cap);
|
|
193
|
+
const { written } = keyEncoder.encodeInto(key, keyBuf);
|
|
194
|
+
computeLanes(keyBuf, seed, written);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const bytes = normalize(key);
|
|
198
|
+
computeLanes(bytes, seed, bytes.length);
|
|
199
|
+
}
|
|
200
|
+
function hash128KeyInto(key, seed, out) {
|
|
201
|
+
keyToLanes(key, seed);
|
|
202
|
+
out.h1lo = LANES.h1lo;
|
|
203
|
+
out.h1hi = LANES.h1hi;
|
|
204
|
+
out.h2lo = LANES.h2lo;
|
|
205
|
+
out.h2hi = LANES.h2hi;
|
|
183
206
|
}
|
|
184
207
|
function reduce(x, range) {
|
|
185
208
|
const xlo = x & 65535;
|
|
@@ -199,9 +222,9 @@ function reduce(x, range) {
|
|
|
199
222
|
* (the RocksDB `+i^2` fix), reduced into range with Lemire multiply-shift.
|
|
200
223
|
*/
|
|
201
224
|
function probeInto(key, count, range, seed, out) {
|
|
202
|
-
|
|
203
|
-
const a = (h1lo ^ h1hi) >>> 0;
|
|
204
|
-
const b = (h2lo ^ h2hi) >>> 0;
|
|
225
|
+
keyToLanes(key, seed);
|
|
226
|
+
const a = (LANES.h1lo ^ LANES.h1hi) >>> 0;
|
|
227
|
+
const b = (LANES.h2lo ^ LANES.h2hi) >>> 0;
|
|
205
228
|
for (let i = 0; i < count; i++) out[i] = reduce(a + Math.imul(i, b) + i * i >>> 0, range);
|
|
206
229
|
}
|
|
207
230
|
//#endregion
|
|
@@ -268,4 +291,4 @@ function readHeader(frame) {
|
|
|
268
291
|
};
|
|
269
292
|
}
|
|
270
293
|
//#endregion
|
|
271
|
-
export { probeInto as a,
|
|
294
|
+
export { probeInto as a, hash128KeyInto as i, readHeader as n, reduce as o, writeHeader as r, SerializationError as t };
|
|
@@ -13,6 +13,12 @@ const C2LO = 658871167;
|
|
|
13
13
|
const C2HI = 1291169091;
|
|
14
14
|
let RLO = 0;
|
|
15
15
|
let RHI = 0;
|
|
16
|
+
const LANES = {
|
|
17
|
+
h1lo: 0,
|
|
18
|
+
h1hi: 0,
|
|
19
|
+
h2lo: 0,
|
|
20
|
+
h2hi: 0
|
|
21
|
+
};
|
|
16
22
|
function mul64(alo, ahi, blo, bhi) {
|
|
17
23
|
const a0 = alo & 65535;
|
|
18
24
|
const a1 = alo >>> 16;
|
|
@@ -75,8 +81,7 @@ function fmix64(lo, hi) {
|
|
|
75
81
|
RLO = l;
|
|
76
82
|
RHI = h;
|
|
77
83
|
}
|
|
78
|
-
function
|
|
79
|
-
const len = bytes.length;
|
|
84
|
+
function computeLanes(bytes, seed, len) {
|
|
80
85
|
const nblocks = len >>> 4;
|
|
81
86
|
let h1lo = seed >>> 0;
|
|
82
87
|
let h1hi = 0;
|
|
@@ -174,12 +179,30 @@ function hash128(bytes, seed = 0) {
|
|
|
174
179
|
add64(h2lo, h2hi, h1lo, h1hi);
|
|
175
180
|
h2lo = RLO;
|
|
176
181
|
h2hi = RHI;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
LANES.h1lo = h1lo >>> 0;
|
|
183
|
+
LANES.h1hi = h1hi >>> 0;
|
|
184
|
+
LANES.h2lo = h2lo >>> 0;
|
|
185
|
+
LANES.h2hi = h2hi >>> 0;
|
|
186
|
+
}
|
|
187
|
+
const keyEncoder = new TextEncoder();
|
|
188
|
+
let keyBuf = /* @__PURE__ */ new Uint8Array(256);
|
|
189
|
+
function keyToLanes(key, seed) {
|
|
190
|
+
if (typeof key === "string") {
|
|
191
|
+
const cap = key.length * 3;
|
|
192
|
+
if (keyBuf.length < cap) keyBuf = new Uint8Array(cap);
|
|
193
|
+
const { written } = keyEncoder.encodeInto(key, keyBuf);
|
|
194
|
+
computeLanes(keyBuf, seed, written);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const bytes = normalize(key);
|
|
198
|
+
computeLanes(bytes, seed, bytes.length);
|
|
199
|
+
}
|
|
200
|
+
function hash128KeyInto(key, seed, out) {
|
|
201
|
+
keyToLanes(key, seed);
|
|
202
|
+
out.h1lo = LANES.h1lo;
|
|
203
|
+
out.h1hi = LANES.h1hi;
|
|
204
|
+
out.h2lo = LANES.h2lo;
|
|
205
|
+
out.h2hi = LANES.h2hi;
|
|
183
206
|
}
|
|
184
207
|
function reduce(x, range) {
|
|
185
208
|
const xlo = x & 65535;
|
|
@@ -199,9 +222,9 @@ function reduce(x, range) {
|
|
|
199
222
|
* (the RocksDB `+i^2` fix), reduced into range with Lemire multiply-shift.
|
|
200
223
|
*/
|
|
201
224
|
function probeInto(key, count, range, seed, out) {
|
|
202
|
-
|
|
203
|
-
const a = (h1lo ^ h1hi) >>> 0;
|
|
204
|
-
const b = (h2lo ^ h2hi) >>> 0;
|
|
225
|
+
keyToLanes(key, seed);
|
|
226
|
+
const a = (LANES.h1lo ^ LANES.h1hi) >>> 0;
|
|
227
|
+
const b = (LANES.h2lo ^ LANES.h2hi) >>> 0;
|
|
205
228
|
for (let i = 0; i < count; i++) out[i] = reduce(a + Math.imul(i, b) + i * i >>> 0, range);
|
|
206
229
|
}
|
|
207
230
|
//#endregion
|
|
@@ -274,16 +297,10 @@ Object.defineProperty(exports, "SerializationError", {
|
|
|
274
297
|
return SerializationError;
|
|
275
298
|
}
|
|
276
299
|
});
|
|
277
|
-
Object.defineProperty(exports, "
|
|
278
|
-
enumerable: true,
|
|
279
|
-
get: function() {
|
|
280
|
-
return hash128;
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
Object.defineProperty(exports, "normalize", {
|
|
300
|
+
Object.defineProperty(exports, "hash128KeyInto", {
|
|
284
301
|
enumerable: true,
|
|
285
302
|
get: function() {
|
|
286
|
-
return
|
|
303
|
+
return hash128KeyInto;
|
|
287
304
|
}
|
|
288
305
|
});
|
|
289
306
|
Object.defineProperty(exports, "probeInto", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "distillate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Probabilistic data structures for JavaScript. Space-efficient, approximate-membership filters (Bloom, Blocked Bloom, Binary Fuse) with tunable error and a portable binary format; zero dependencies, universal.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bloom-filter",
|
|
@@ -63,23 +63,6 @@
|
|
|
63
63
|
"files": [
|
|
64
64
|
"dist"
|
|
65
65
|
],
|
|
66
|
-
"scripts": {
|
|
67
|
-
"build": "tsdown",
|
|
68
|
-
"publint": "publint --strict",
|
|
69
|
-
"check": "publint --strict && attw --pack . --profile node16",
|
|
70
|
-
"attw": "attw --pack . --profile node16",
|
|
71
|
-
"test": "vitest run",
|
|
72
|
-
"changeset": "changeset",
|
|
73
|
-
"version": "changeset version",
|
|
74
|
-
"release": "changeset publish",
|
|
75
|
-
"bench": "tsx bench/core.bench.ts && tsx bench/bloom.bench.ts && tsx bench/blocked.bench.ts && tsx bench/fuse.bench.ts",
|
|
76
|
-
"typecheck": "tsc --noEmit",
|
|
77
|
-
"format": "prettier --write .",
|
|
78
|
-
"format:check": "prettier --check .",
|
|
79
|
-
"lint": "eslint .",
|
|
80
|
-
"lint:fix": "eslint . --fix",
|
|
81
|
-
"prepare": "husky"
|
|
82
|
-
},
|
|
83
66
|
"lint-staged": {
|
|
84
67
|
"*.ts": [
|
|
85
68
|
"eslint --fix --no-warn-ignored",
|
|
@@ -93,6 +76,7 @@
|
|
|
93
76
|
"@commitlint/cli": "^21.2.1",
|
|
94
77
|
"@commitlint/config-conventional": "^21.2.0",
|
|
95
78
|
"@eslint/js": "^10.0.1",
|
|
79
|
+
"@types/node": "^26.1.2",
|
|
96
80
|
"eslint": "^10.8.0",
|
|
97
81
|
"eslint-config-prettier": "^10.1.8",
|
|
98
82
|
"fast-check": "^4.9.0",
|
|
@@ -110,5 +94,20 @@
|
|
|
110
94
|
"engines": {
|
|
111
95
|
"node": ">=20"
|
|
112
96
|
},
|
|
113
|
-
"
|
|
114
|
-
|
|
97
|
+
"scripts": {
|
|
98
|
+
"build": "tsdown",
|
|
99
|
+
"publint": "publint --strict",
|
|
100
|
+
"check": "publint --strict && attw --pack . --profile node16",
|
|
101
|
+
"attw": "attw --pack . --profile node16",
|
|
102
|
+
"test": "vitest run",
|
|
103
|
+
"changeset": "changeset",
|
|
104
|
+
"version": "changeset version",
|
|
105
|
+
"release": "changeset publish",
|
|
106
|
+
"bench": "tsx bench/core.bench.ts && tsx bench/bloom.bench.ts && tsx bench/blocked.bench.ts && tsx bench/fuse.bench.ts && tsx bench/accuracy.bench.ts",
|
|
107
|
+
"typecheck": "tsc --noEmit",
|
|
108
|
+
"format": "prettier --write .",
|
|
109
|
+
"format:check": "prettier --check .",
|
|
110
|
+
"lint": "eslint .",
|
|
111
|
+
"lint:fix": "eslint . --fix"
|
|
112
|
+
}
|
|
113
|
+
}
|