Skip to content

ScalableBloomFilter

Defined in: packages/distillate/src/scalable/scalable.ts:159

A Bloom filter that grows with its key count and keeps its false-positive rate under epsilon, for when the number of keys is not known up front.

It is a chain of Bloom stages. Stage i holds n * growth ** i keys at a false-positive target of epsilon * (1 - tightening) * tightening ** i; those targets sum to at most epsilon, however many stages open.

const seen = ScalableBloomFilter.create(1000, 0.01);
seen.add("alice");
seen.has("alice"); // true

new ScalableBloomFilter(params): ScalableBloomFilter

Defined in: packages/distillate/src/scalable/scalable.ts:217

ScalableBloomParams

The filter’s settings.

ScalableBloomFilter

ParamError if a setting is out of range, or the first stage would need more than 2^32 - 1 bits.

get bitsPerKey(): number

Defined in: packages/distillate/src/scalable/scalable.ts:622

Analytic design bits-per-key, m / capacity.

number


get capacity(): number

Defined in: packages/distillate/src/scalable/scalable.ts:607

Keys the open stages hold between them before the next one opens.

number


get count(): number

Defined in: packages/distillate/src/scalable/scalable.ts:602

Keys added that the filter did not already hold.

number


get epsilon(): number

Defined in: packages/distillate/src/scalable/scalable.ts:632

Target false-positive rate for the whole chain.

number


get growth(): number

Defined in: packages/distillate/src/scalable/scalable.ts:637

Capacity multiplier from one stage to the next.

number


get m(): number

Defined in: packages/distillate/src/scalable/scalable.ts:617

Total bits across every stage.

number


get seed(): number

Defined in: packages/distillate/src/scalable/scalable.ts:627

Hash seed shared by every stage.

number


get stages(): number

Defined in: packages/distillate/src/scalable/scalable.ts:612

Number of open stages.

number


get tightening(): number

Defined in: packages/distillate/src/scalable/scalable.ts:642

False-positive target multiplier from one stage to the next.

number

add(key): void

Defined in: packages/distillate/src/scalable/scalable.ts:357

Adds a key. A key the filter already holds is not counted again, so duplicates never use up a stage’s capacity.

BytesLike

The key to insert, as a string or bytes.

void

RangeError if the next stage would need more than 2^32 - 1 bits; the filter is left unchanged and still answers queries.


equals(other): boolean

Defined in: packages/distillate/src/scalable/scalable.ts:459

Tests structural equality: identical settings, the same stages with the same counts, and identical bits, which is exactly when the two serialize to the same bytes. Which stage a key lands in depends on when it arrived, so two filters given the same keys in a different order can be unequal.

ScalableBloomFilter

The filter to compare against.

boolean

true if the two filters are identical.


has(key): boolean

Defined in: packages/distillate/src/scalable/scalable.ts:382

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/scalable/scalable.ts:395

Estimates the chain’s current false-positive rate from each stage’s actual fill: a key is a false positive if any stage wrongly holds it, so this is 1 - prod(1 - (setBits / m) ** k). It rises as keys are added and stays under epsilon while every stage is within its capacity.

number

The estimated false-positive rate, in [0, 1].


toBytes(): Uint8Array

Defined in: packages/distillate/src/scalable/scalable.ts:551

Serializes the filter to a portable little-endian frame, DSTL type 6.

Uint8Array

The serialized filter, readable by ScalableBloomFilter.fromBytes.


toJSON(): FilterJSON

Defined in: packages/distillate/src/scalable/scalable.ts:587

Serializes the filter to a JSON-friendly envelope wrapping the base64 of ScalableBloomFilter.toBytes.

FilterJSON

The JSON envelope.


union(other): ScalableBloomFilter

Defined in: packages/distillate/src/scalable/scalable.ts:413

Returns a new filter holding every key of this filter and other. Stage i of the result is the OR of both inputs’ stage i, and the result has the longer of the two chains. Each stage’s count becomes the smaller of its capacity and the two counts summed: an upper bound, so the merged chain opens its next stage early rather than late.

ScalableBloomFilter

A filter built with identical settings.

ScalableBloomFilter

A new filter; neither input is changed.

ScalableParamMismatchError if any setting, or the geometry of a stage both filters have, differs.


static create(n, epsilon, options?): ScalableBloomFilter

Defined in: packages/distillate/src/scalable/scalable.ts:179

Creates a filter whose first stage holds n keys, for a chain-wide false-positive target.

number

Keys the first stage holds.

number

Target false-positive rate for the whole chain.

ScalableBloomOptions = {}

Optional growth, tightening and seed.

ScalableBloomFilter

A new, empty filter.


static from(keys, epsilon, options?): ScalableBloomFilter

Defined in: packages/distillate/src/scalable/scalable.ts:197

Builds a filter from keys, with the first stage sized for their count; it keeps growing as more keys arrive. Duplicates only oversize the first stage, since a key already held is not counted again.

Iterable<BytesLike>

The keys to insert.

number

Target false-positive rate for the whole chain.

ScalableBloomOptions = {}

Optional growth, tightening and seed.

ScalableBloomFilter

A new filter containing every key.


static fromBytes(bytes): ScalableBloomFilter

Defined in: packages/distillate/src/scalable/scalable.ts:482

Restores a filter from its ScalableBloomFilter.toBytes serialization.

Uint8Array

A frame produced by toBytes.

ScalableBloomFilter

The reconstructed filter.

SerializationError (or a subclass) if the frame is malformed.


static fromJSON(value): ScalableBloomFilter

Defined in: packages/distillate/src/scalable/scalable.ts:597

Restores a filter from its ScalableBloomFilter.toJSON envelope.

unknown

The JSON envelope.

ScalableBloomFilter

The reconstructed filter.