Skip to content

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.

const filter = BloomFilter.create(100_000, 0.01);
filter.add("alice");
filter.has("alice"); // true
filter.has("bob"); // false (or a ~1% false positive)

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.

BloomParams

BloomFilter

get bitsPerKey(): number

Defined in: packages/distillate/src/bloom/bloom.ts:172

Analytic design bits-per-key m / n.

number


get k(): number

Defined in: packages/distillate/src/bloom/bloom.ts:157

Number of hash probes per key.

number


get length(): number

Defined in: packages/distillate/src/bloom/bloom.ts:167

Number of bits currently set.

number


get m(): number

Defined in: packages/distillate/src/bloom/bloom.ts:152

Number of bits in the filter.

number


get seed(): number

Defined in: packages/distillate/src/bloom/bloom.ts:162

Hash seed.

number

add(key): void

Defined in: packages/distillate/src/bloom/bloom.ts:272

Adds a key to the set.

BytesLike

The key to insert, as a string or bytes.

void


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.

BloomFilter

The filter to compare against.

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.

BytesLike

The key to test.

boolean

true if present (possibly a false positive); false guarantees absence.


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.

number

The estimated false-positive rate, 0 for an empty filter.


toBytes(): Uint8Array

Defined in: packages/distillate/src/bloom/bloom.ts:192

Serializes the filter to a portable little-endian byte layout.

Uint8Array

The serialized filter, readable by BloomFilter.fromBytes.


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.

FilterJSON

The envelope, readable by BloomFilter.fromJSON.


union(other): BloomFilter

Defined in: packages/distillate/src/bloom/bloom.ts:245

Returns a new filter containing the union of this filter and other.

BloomFilter

A filter built with identical parameters.

BloomFilter

A new filter reporting membership for keys in either input.

BloomParamMismatchError if the parameters differ.


static create(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.

number

Expected number of keys.

number

Target false-positive rate, e.g. 0.01 for 1%.

BloomFilter

A new, empty filter.


static from(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.

Iterable<BytesLike>

The keys to insert.

number

Target false-positive rate, e.g. 0.01 for 1%.

BloomFilter

A new filter containing every key.


static fromBytes(bytes): BloomFilter

Defined in: packages/distillate/src/bloom/bloom.ts:100

Restores a filter from its BloomFilter.toBytes serialization.

Uint8Array

The serialized filter.

BloomFilter

The reconstructed filter.


static fromJSON(value): BloomFilter

Defined in: packages/distillate/src/bloom/bloom.ts:234

Restores a filter from its BloomFilter.toJSON envelope.

unknown

The JSON envelope.

BloomFilter

The reconstructed filter.