BloomFilter
Defined in: packages/distillate/src/bloom/bloom.ts:56
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:128
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:172
Analytic design bits-per-key m / n.
Returns
Section titled “Returns”number
Get Signature
Section titled “Get Signature”get k():
number
Defined in: packages/distillate/src/bloom/bloom.ts:157
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:167
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:152
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:162
Hash seed.
Returns
Section titled “Returns”number
Methods
Section titled “Methods”add(
key):void
Defined in: packages/distillate/src/bloom/bloom.ts:272
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:214
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:283
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:183
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:192
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:224
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:245
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:71
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:87
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:100
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:234
Restores a filter from its BloomFilter.toJSON envelope.
Parameters
Section titled “Parameters”unknown
The JSON envelope.
Returns
Section titled “Returns”BloomFilter
The reconstructed filter.