distillate 0.1.0 → 0.1.2

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/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  //#region src/index.d.ts
2
- declare const VERSION = "0.1.0";
2
+ /** The installed `distillate` package version. */
3
+ declare const VERSION: string;
3
4
  //#endregion
4
5
  export { VERSION };
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
+ //#endregion
1
2
  //#region src/index.ts
2
- const VERSION = "0.1.0";
3
+ /** The installed `distillate` package version. */
4
+ const VERSION = "0.1.2";
3
5
  //#endregion
4
6
  export { VERSION };
@@ -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 hash128(bytes, seed = 0) {
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
- return {
178
- h1lo: h1lo >>> 0,
179
- h1hi: h1hi >>> 0,
180
- h2lo: h2lo >>> 0,
181
- h2hi: h2hi >>> 0
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
- const { h1lo, h1hi, h2lo, h2hi } = hash128(normalize(key), seed);
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, hash128 as i, readHeader as n, reduce as o, writeHeader as r, normalize as s, SerializationError as t };
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 hash128(bytes, seed = 0) {
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
- return {
178
- h1lo: h1lo >>> 0,
179
- h1hi: h1hi >>> 0,
180
- h2lo: h2lo >>> 0,
181
- h2hi: h2hi >>> 0
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
- const { h1lo, h1hi, h2lo, h2hi } = hash128(normalize(key), seed);
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, "hash128", {
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 normalize;
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.0",
3
+ "version": "0.1.2",
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,8 +76,12 @@
93
76
  "@commitlint/cli": "^21.2.1",
94
77
  "@commitlint/config-conventional": "^21.2.0",
95
78
  "@eslint/js": "^10.0.1",
79
+ "@microsoft/api-extractor": "^7.58.12",
80
+ "@types/node": "^26.1.2",
81
+ "@vitest/coverage-v8": "^4.1.10",
96
82
  "eslint": "^10.8.0",
97
83
  "eslint-config-prettier": "^10.1.8",
84
+ "eslint-plugin-tsdoc": "^0.5.2",
98
85
  "fast-check": "^4.9.0",
99
86
  "husky": "^9.1.7",
100
87
  "lint-staged": "^17.2.0",
@@ -103,6 +90,8 @@
103
90
  "publint": "^0.3.22",
104
91
  "tsdown": "^0.22.14",
105
92
  "tsx": "^4.23.1",
93
+ "typedoc": "^0.28.20",
94
+ "typedoc-plugin-markdown": "^4.12.0",
106
95
  "typescript": "^5.9.3",
107
96
  "typescript-eslint": "^8.65.0",
108
97
  "vitest": "^4.1.10"
@@ -110,5 +99,24 @@
110
99
  "engines": {
111
100
  "node": ">=20"
112
101
  },
113
- "packageManager": "pnpm@10.33.0"
114
- }
102
+ "scripts": {
103
+ "build": "tsdown",
104
+ "publint": "publint --strict",
105
+ "check": "publint --strict && attw --pack . --profile node16",
106
+ "attw": "attw --pack . --profile node16",
107
+ "test": "vitest run",
108
+ "coverage": "vitest run --coverage",
109
+ "api:report": "node scripts/api-extractor.mjs --local",
110
+ "api:check": "node scripts/api-extractor.mjs",
111
+ "docs:api": "typedoc",
112
+ "changeset": "changeset",
113
+ "version": "changeset version",
114
+ "release": "changeset publish",
115
+ "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",
116
+ "typecheck": "tsc --noEmit",
117
+ "format": "prettier --write .",
118
+ "format:check": "prettier --check .",
119
+ "lint": "eslint .",
120
+ "lint:fix": "eslint . --fix"
121
+ }
122
+ }