distillate 0.2.0 → 0.3.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.
@@ -77,6 +77,26 @@ var BlockedBloomFilter = class BlockedBloomFilter {
77
77
  get bitsPerKey() {
78
78
  return this.#numBlocks * 256 / this.#n;
79
79
  }
80
+ /** Number of bits currently set across all lanes. */
81
+ get length() {
82
+ let bits = 0;
83
+ for (let w of this.#lanes) while (w) {
84
+ w &= w - 1;
85
+ bits++;
86
+ }
87
+ return bits;
88
+ }
89
+ /**
90
+ * Estimates the current false-positive rate from the actual fill,
91
+ * `(length / totalBits) ** 8`. A split-block query checks exactly 8 lane-bits,
92
+ * so the exponent is 8 rather than a classic probe count `k`. This reflects
93
+ * how full the filter is right now, not the design target.
94
+ *
95
+ * @returns The estimated false-positive rate, `0` for an empty filter.
96
+ */
97
+ rate() {
98
+ return (this.length / (this.#numBlocks * 256)) ** 8;
99
+ }
80
100
  /**
81
101
  * Restores a filter from its {@link BlockedBloomFilter.toBytes} serialization.
82
102
  *
@@ -43,6 +43,17 @@ declare class BlockedBloomFilter {
43
43
  constructor({ bitsPerKey, capacity, seed }: BlockedBloomParams);
44
44
  /** Actual bits allocated per key (`total bits / capacity`). */
45
45
  get bitsPerKey(): number;
46
+ /** Number of bits currently set across all lanes. */
47
+ get length(): number;
48
+ /**
49
+ * Estimates the current false-positive rate from the actual fill,
50
+ * `(length / totalBits) ** 8`. A split-block query checks exactly 8 lane-bits,
51
+ * so the exponent is 8 rather than a classic probe count `k`. This reflects
52
+ * how full the filter is right now, not the design target.
53
+ *
54
+ * @returns The estimated false-positive rate, `0` for an empty filter.
55
+ */
56
+ rate(): number;
46
57
  /**
47
58
  * Restores a filter from its {@link BlockedBloomFilter.toBytes} serialization.
48
59
  *
@@ -43,6 +43,17 @@ declare class BlockedBloomFilter {
43
43
  constructor({ bitsPerKey, capacity, seed }: BlockedBloomParams);
44
44
  /** Actual bits allocated per key (`total bits / capacity`). */
45
45
  get bitsPerKey(): number;
46
+ /** Number of bits currently set across all lanes. */
47
+ get length(): number;
48
+ /**
49
+ * Estimates the current false-positive rate from the actual fill,
50
+ * `(length / totalBits) ** 8`. A split-block query checks exactly 8 lane-bits,
51
+ * so the exponent is 8 rather than a classic probe count `k`. This reflects
52
+ * how full the filter is right now, not the design target.
53
+ *
54
+ * @returns The estimated false-positive rate, `0` for an empty filter.
55
+ */
56
+ rate(): number;
46
57
  /**
47
58
  * Restores a filter from its {@link BlockedBloomFilter.toBytes} serialization.
48
59
  *
@@ -76,6 +76,26 @@ var BlockedBloomFilter = class BlockedBloomFilter {
76
76
  get bitsPerKey() {
77
77
  return this.#numBlocks * 256 / this.#n;
78
78
  }
79
+ /** Number of bits currently set across all lanes. */
80
+ get length() {
81
+ let bits = 0;
82
+ for (let w of this.#lanes) while (w) {
83
+ w &= w - 1;
84
+ bits++;
85
+ }
86
+ return bits;
87
+ }
88
+ /**
89
+ * Estimates the current false-positive rate from the actual fill,
90
+ * `(length / totalBits) ** 8`. A split-block query checks exactly 8 lane-bits,
91
+ * so the exponent is 8 rather than a classic probe count `k`. This reflects
92
+ * how full the filter is right now, not the design target.
93
+ *
94
+ * @returns The estimated false-positive rate, `0` for an empty filter.
95
+ */
96
+ rate() {
97
+ return (this.length / (this.#numBlocks * 256)) ** 8;
98
+ }
79
99
  /**
80
100
  * Restores a filter from its {@link BlockedBloomFilter.toBytes} serialization.
81
101
  *
@@ -122,11 +122,37 @@ var BloomFilter = class BloomFilter {
122
122
  this.#scratch = new Uint32Array(k);
123
123
  this.#n = Math.round(m * Math.LN2 / k);
124
124
  }
125
+ /** Number of bits in the filter. */
126
+ get m() {
127
+ return this.#m;
128
+ }
129
+ /** Number of hash probes per key. */
130
+ get k() {
131
+ return this.#k;
132
+ }
133
+ /** Hash seed. */
134
+ get seed() {
135
+ return this.#seed;
136
+ }
137
+ /** Number of bits currently set. */
138
+ get length() {
139
+ return this.#bits.count();
140
+ }
125
141
  /** Analytic design bits-per-key `m / n`. */
126
142
  get bitsPerKey() {
127
143
  return this.#m / this.#n;
128
144
  }
129
145
  /**
146
+ * Estimates the current false-positive rate from the actual fill,
147
+ * `(length / m) ** k`. This reflects how full the filter is right now, not
148
+ * the design target; it rises as keys are added.
149
+ *
150
+ * @returns The estimated false-positive rate, `0` for an empty filter.
151
+ */
152
+ rate() {
153
+ return (this.length / this.#m) ** this.#k;
154
+ }
155
+ /**
130
156
  * Serializes the filter to a portable little-endian byte layout.
131
157
  *
132
158
  * @returns The serialized filter, readable by {@link BloomFilter.fromBytes}.
@@ -49,8 +49,24 @@ declare class BloomFilter {
49
49
  * {@link BloomFilter.create} unless restoring a specific configuration.
50
50
  */
51
51
  constructor({ m, k, seed }: BloomParams);
52
+ /** Number of bits in the filter. */
53
+ get m(): number;
54
+ /** Number of hash probes per key. */
55
+ get k(): number;
56
+ /** Hash seed. */
57
+ get seed(): number;
58
+ /** Number of bits currently set. */
59
+ get length(): number;
52
60
  /** Analytic design bits-per-key `m / n`. */
53
61
  get bitsPerKey(): number;
62
+ /**
63
+ * Estimates the current false-positive rate from the actual fill,
64
+ * `(length / m) ** k`. This reflects how full the filter is right now, not
65
+ * the design target; it rises as keys are added.
66
+ *
67
+ * @returns The estimated false-positive rate, `0` for an empty filter.
68
+ */
69
+ rate(): number;
54
70
  /**
55
71
  * Serializes the filter to a portable little-endian byte layout.
56
72
  *
@@ -49,8 +49,24 @@ declare class BloomFilter {
49
49
  * {@link BloomFilter.create} unless restoring a specific configuration.
50
50
  */
51
51
  constructor({ m, k, seed }: BloomParams);
52
+ /** Number of bits in the filter. */
53
+ get m(): number;
54
+ /** Number of hash probes per key. */
55
+ get k(): number;
56
+ /** Hash seed. */
57
+ get seed(): number;
58
+ /** Number of bits currently set. */
59
+ get length(): number;
52
60
  /** Analytic design bits-per-key `m / n`. */
53
61
  get bitsPerKey(): number;
62
+ /**
63
+ * Estimates the current false-positive rate from the actual fill,
64
+ * `(length / m) ** k`. This reflects how full the filter is right now, not
65
+ * the design target; it rises as keys are added.
66
+ *
67
+ * @returns The estimated false-positive rate, `0` for an empty filter.
68
+ */
69
+ rate(): number;
54
70
  /**
55
71
  * Serializes the filter to a portable little-endian byte layout.
56
72
  *
@@ -121,11 +121,37 @@ var BloomFilter = class BloomFilter {
121
121
  this.#scratch = new Uint32Array(k);
122
122
  this.#n = Math.round(m * Math.LN2 / k);
123
123
  }
124
+ /** Number of bits in the filter. */
125
+ get m() {
126
+ return this.#m;
127
+ }
128
+ /** Number of hash probes per key. */
129
+ get k() {
130
+ return this.#k;
131
+ }
132
+ /** Hash seed. */
133
+ get seed() {
134
+ return this.#seed;
135
+ }
136
+ /** Number of bits currently set. */
137
+ get length() {
138
+ return this.#bits.count();
139
+ }
124
140
  /** Analytic design bits-per-key `m / n`. */
125
141
  get bitsPerKey() {
126
142
  return this.#m / this.#n;
127
143
  }
128
144
  /**
145
+ * Estimates the current false-positive rate from the actual fill,
146
+ * `(length / m) ** k`. This reflects how full the filter is right now, not
147
+ * the design target; it rises as keys are added.
148
+ *
149
+ * @returns The estimated false-positive rate, `0` for an empty filter.
150
+ */
151
+ rate() {
152
+ return (this.length / this.#m) ** this.#k;
153
+ }
154
+ /**
129
155
  * Serializes the filter to a portable little-endian byte layout.
130
156
  *
131
157
  * @returns The serialized filter, readable by {@link BloomFilter.fromBytes}.
package/dist/index.cjs CHANGED
@@ -2,6 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#endregion
3
3
  //#region src/index.ts
4
4
  /** The installed `distillate` package version. */
5
- const VERSION = "0.2.0";
5
+ const VERSION = "0.3.0";
6
6
  //#endregion
7
7
  exports.VERSION = VERSION;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  //#endregion
2
2
  //#region src/index.ts
3
3
  /** The installed `distillate` package version. */
4
- const VERSION = "0.2.0";
4
+ const VERSION = "0.3.0";
5
5
  //#endregion
6
6
  export { VERSION };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "distillate",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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",