Skip to content

CuckooFilter

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:48

Approximate set membership with deletion, the thing a Bloom filter cannot do.

Stores a short fingerprint of each item in one of two candidate buckets. The second bucket is derived from the first by XOR with the fingerprint’s hash, which is what makes the relation symmetric: from either bucket the other can be computed without the item, so a fingerprint can be relocated during insertion and found again during lookup.

Deleting removes one copy of a fingerprint. Only delete items actually inserted: removing a fingerprint that a different item happens to share would introduce a false negative, which this structure otherwise never has.

add can fail. When both candidate buckets are full, it evicts and relocates up to maxKicks times; past that the filter is too loaded and add returns false. A failed insert is rolled back, so the filter still holds exactly what it held before — no previously inserted item is ever displaced into nothing.

Time complexity: O(1) for has and delete — exactly two bucket probes. add is O(1) amortised, degrading as the load factor approaches capacity.

T

The item type.

new CuckooFilter<T>(iterable, options): CuckooFilter<T>

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:61

Iterable<T, any, any> | undefined

CuckooFilterOptions<T>

CuckooFilter<T>

readonly bucketSize: number

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:55

Fingerprints per bucket.

add(item): boolean

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:117

O(1) amortised.

T

boolean

false if the filter was too full to place the item, after maxKicks relocations. The filter is rolled back to exactly its prior contents, so nothing inserted earlier is lost.


addAll(items): number

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:169

Iterable<T>

number

How many items were added. A shortfall means the filter filled up — see add.


clear(): void

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:105

void


count(): number

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:96

How many fingerprints are stored.

number


delete(item): boolean

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:204

Removes one copy of the item’s fingerprint. O(1).

T

boolean

true if a matching fingerprint was removed. Deleting an item never inserted can remove a colliding item’s fingerprint instead, which is the one way this filter can produce a false negative.


has(item): boolean

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:187

O(1), two bucket probes.

T

boolean

false means the item is definitely absent, provided only inserted items were ever deleted. true means probably present.


loadFactor(): number

Defined in: packages/data/src/probabilistic/cuckoo-filter.ts:101

The fraction of slots in use.

number