BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:71
A classic Bloom filter: a space-efficient set with a tunable false-positive rate and zero false negatives.
Example
Section titled “Example”const filter = BloomFilter.create(100_000, 0.01);filter.add("alice");filter.has("alice"); // truefilter.has("bob"); // false (or a ~1% false positive)Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new BloomFilter(
__namedParameters):BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:146
Constructs a filter from low-level BloomParams. Prefer BloomFilter.create unless restoring a specific configuration.
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”Returns
Section titled “Returns”BloomFilter
Accessors
Section titled “Accessors”bitsPerKey
Section titled “bitsPerKey”Get Signature
Section titled “Get Signature”get bitsPerKey():
number
Defined in: packages/distillate/src/bloom/bloom.ts:196
Analytic design bits-per-key, m / n.
A filter built without an explicit n derives one as m * ln2 / k, the
count its geometry is optimal for. That need not be the count the
geometry was solved for, so the same m and k can report a different
cost depending on how the filter was constructed. create and
fromBytes always carry the real n.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get k():
number
Defined in: packages/distillate/src/bloom/bloom.ts:173
Number of hash probes per key.
Returns
Section titled “Returns”number
length
Section titled “length”Get Signature
Section titled “Get Signature”get length():
number
Defined in: packages/distillate/src/bloom/bloom.ts:183
Number of bits currently set.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get m():
number
Defined in: packages/distillate/src/bloom/bloom.ts:168
Number of bits in the filter.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get seed():
number
Defined in: packages/distillate/src/bloom/bloom.ts:178
Hash seed.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”add(
key):void
Defined in: packages/distillate/src/bloom/bloom.ts:299
Adds a key to the set.
Parameters
Section titled “Parameters”BytesLike
The key to insert, as a string or bytes.
Returns
Section titled “Returns”void
equals()
Section titled “equals()”equals(
other):boolean
Defined in: packages/distillate/src/bloom/bloom.ts:239
Tests structural equality: true when other serializes to identical
bytes, meaning identical parameters and set bits.
Parameters
Section titled “Parameters”BloomFilter
The filter to compare against.
Returns
Section titled “Returns”boolean
true if the two filters are byte-for-byte identical.
has(
key):boolean
Defined in: packages/distillate/src/bloom/bloom.ts:310
Tests whether a key is in the set.
Parameters
Section titled “Parameters”BytesLike
The key to test.
Returns
Section titled “Returns”boolean
true if present (possibly a false positive); false guarantees absence.
rate()
Section titled “rate()”rate():
number
Defined in: packages/distillate/src/bloom/bloom.ts:207
Estimates the current false-positive rate from the actual fill,
(length / m) ** k. This reflects how full the filter is right now, not
the design target; it rises as keys are added.
Returns
Section titled “Returns”number
The estimated false-positive rate, 0 for an empty filter.
toBytes()
Section titled “toBytes()”toBytes():
Uint8Array
Defined in: packages/distillate/src/bloom/bloom.ts:216
Serializes the filter to a portable little-endian byte layout.
Returns
Section titled “Returns”Uint8Array
The serialized filter, readable by BloomFilter.fromBytes.
toJSON()
Section titled “toJSON()”toJSON():
FilterJSON
Defined in: packages/distillate/src/bloom/bloom.ts:249
Serializes the filter to a JSON-friendly envelope wrapping the base64 of BloomFilter.toBytes.
Returns
Section titled “Returns”The envelope, readable by BloomFilter.fromJSON.
union()
Section titled “union()”union(
other):BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:270
Returns a new filter containing the union of this filter and other.
Parameters
Section titled “Parameters”BloomFilter
A filter built with identical parameters.
Returns
Section titled “Returns”BloomFilter
A new filter reporting membership for keys in either input.
Throws
Section titled “Throws”BloomParamMismatchError if the parameters differ.
create()
Section titled “create()”
staticcreate(n,epsilon):BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:86
Creates a filter sized for n expected keys at a target false-positive rate.
Parameters
Section titled “Parameters”number
Expected number of keys.
epsilon
Section titled “epsilon”number
Target false-positive rate, e.g. 0.01 for 1%.
Returns
Section titled “Returns”BloomFilter
A new, empty filter.
from()
Section titled “from()”
staticfrom(keys,epsilon):BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:102
Builds a filter from keys, sized for their count at the target
false-positive rate. The ergonomic entry point when the key set is already
in hand; use BloomFilter.create to size for a count known ahead.
Parameters
Section titled “Parameters”Iterable<BytesLike>
The keys to insert.
epsilon
Section titled “epsilon”number
Target false-positive rate, e.g. 0.01 for 1%.
Returns
Section titled “Returns”BloomFilter
A new filter containing every key.
fromBytes()
Section titled “fromBytes()”
staticfromBytes(bytes):BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:117
Restores a filter from its BloomFilter.toBytes serialization.
Parameters
Section titled “Parameters”Uint8Array
The serialized filter.
Returns
Section titled “Returns”BloomFilter
The reconstructed filter.
fromJSON()
Section titled “fromJSON()”
staticfromJSON(value):BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:259
Restores a filter from its BloomFilter.toJSON envelope.
Parameters
Section titled “Parameters”unknown
The JSON envelope.
Returns
Section titled “Returns”BloomFilter
The reconstructed filter.