CuckooFilter
Class: CuckooFilter
Cuckoo Filter implementation with 16-bit fingerprints.
Provides O(1) membership testing with support for deletion. False positives are possible (~0.003% at 95% load with 16-bit FP). False negatives are impossible (by design).
Note: This implementation tracks original IDs to enable correct resize. This trades memory for correctness. For space-critical applications, use a fixed-size filter created with fromIds().
Constructors
new CuckooFilter()
new CuckooFilter(options?): CuckooFilterParameters
| Parameter | Type |
|---|---|
options? | CuckooFilterOptions |
Returns
Methods
add()
add(id): booleanAdd an item to the filter.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The record ID to add |
Returns
boolean
true if added successfully, false if resize needed
clear()
clear(): voidClear all items from the filter.
Returns
void
estimateMemoryUsage()
estimateMemoryUsage(): numberEstimate memory usage in bytes.
Returns
number
getCapacity()
getCapacity(): numberGet the capacity (max items before resize).
Returns
number
getCount()
getCount(): numberGet the number of items in the filter.
Returns
number
getLoadFactor()
getLoadFactor(): numberGet the current load factor.
Returns
number
mightContain()
mightContain(id): booleanCheck if an item might be in the filter.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The record ID to check |
Returns
boolean
true if possibly present, false if definitely not present
remove()
remove(id): booleanRemove an item from the filter.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The record ID to remove |
Returns
boolean
true if removed, false if not found
resize()
resize(): voidResize the filter to accommodate more items. Doubles the number of buckets.
We use tracked IDs to properly rehash all items, ensuring no false negatives after resize. This is the only correct way to resize a Cuckoo filter.
Returns
void
serialize()
serialize(): CuckooFilterDataSerialize the filter for persistence.
Returns
deserialize()
static deserialize(data): CuckooFilterDeserialize a filter from persisted data.
Parameters
| Parameter | Type |
|---|---|
data | CuckooFilterData |
Returns
empty()
static empty(options?): CuckooFilterCreate an empty filter.
Parameters
| Parameter | Type |
|---|---|
options? | CuckooFilterOptions |
Returns
fromIds()
static fromIds(ids, options?): CuckooFilterCreate a filter from a set of IDs (bulk load).
Parameters
| Parameter | Type |
|---|---|
ids | string[] |
options? | CuckooFilterOptions |
