Cuckoo Filter
Stores a short fingerprint of each item in one of two candidate buckets, using the same "kick out and relocate" trick as cuckoo hashing. Supports deletion and often beats Bloom filters on space at low false-positive rates.
How it works
Each item is reduced to a short fingerprint (a few bits, e.g. 8) and a first candidate bucket bucketA = hash(item). The second candidate bucket is bucketB = bucketA XOR hash(fingerprint): the "partial-key cuckoo hashing" trick, which means you can recompute either bucket from the other plus the fingerprint alone, without re-hashing the original item. That's what makes deletion possible.
add() places the fingerprint in whichever candidate bucket has a free slot. If both are full, it picks an existing fingerprint at random, evicts ("kicks") it to its alternate bucket, and repeats, cascading evictions just like cuckoo hashing, up to a max-kicks limit before giving up (meaning the filter is too full for its size).
contains() just checks both candidate buckets for the fingerprint, no eviction needed. remove() clears it from whichever bucket holds it.
Interactive demo
API surface
| Operation | Description | Complexity |
|---|---|---|
| new CuckooFilter(buckets, slotsPerBucket?, fpBits?) | Allocate buckets × slotsPerBucket fingerprint slots. | O(buckets × slots) space |
| add(item): boolean | Insert a fingerprint, evicting/relocating on collision. False if max kicks exceeded. | O(1) amortized |
| contains(item): boolean | Check both candidate buckets for the fingerprint. | O(slots) time |
| remove(item): boolean | Clear the fingerprint from whichever bucket holds it. | O(slots) time |
References
Original papers
- Cuckoo Filter: Practically Better Than BloomBin Fan, David G. Andersen, Michael Kaminsky, Michael D. Mitzenmacher · 2014
Library implementations
Real-world use cases
- RedisBloom-documented ad-campaign targeting and coupon-code validation (both need deletion, unlike Bloom filters)
- SDN/NFV and network-security membership testing, packet classification
- Deduplicating URLs/IDs in crawler pipelines where entries need to expire