Overview
A Kirsch-Mitzenmacher double-hashed Bloom filter and a partial-key Cuckoo filter supporting dynamic deletions, fingerprint buckets, and false-positive rate telemetry.
Guided Implementation Walkthrough (4 Progressive Steps)
Step 1: Kirsch-Mitzenmacher Double Hashing
- Core Mechanical Concept: Simulating k Hash Functions with Two Base Hashes
- Target Module:
index.js(BloomFilter._bitPosition) - Engineering Specification: Implement
_bitPosition(item, i)onBloomFilter. Usingh1 = hashA(String(item))andh2 = hashB(String(item)), return((h1 + Math.imul(i, h2)) >>> 0) % this.bitCount. - Verification Invariant: derives k independent bit positions from two base hashes
Step 2: Packed Uint32Array Bitset Operations
- Core Mechanical Concept: Word-Level Bit Addressing via (bit >>> 5) and (1 << (bit & 31))
- Target Module:
index.js(BloomFilter.add / BloomFilter.mightContain) - Engineering Specification: Implement
add(item)andmightContain(item)onBloomFilter. Bitbresides in 32-bit wordb >>> 5at bit offsetb & 31. A Bloom filter guarantees 0% false negatives. - Verification Invariant: guarantees zero false negatives and bounded false positives
Step 3: Partial-Key Cuckoo Hashing via XOR Symmetry
- Core Mechanical Concept: Computing Alternate Bucket from Fingerprint Alone: i2 = i1 ^ hash(fp)
- Target Module:
index.js(CuckooFilter._indices) - Engineering Specification: Implement
_indices(item)onCuckooFilter. Because XOR is an involution ($x \oplus y \oplus y = x$), definingi2 = (i1 ^ hashA(String(fp))) & maskallows us to compute a displaced fingerprint’s alternate bucket from(currentIdx, fp)without storing the original key! - Verification Invariant: computes involutory alternate bucket indices via XOR
Step 4: Cuckoo Kick-Out Displacement & Safe Deletion
- Core Mechanical Concept: Bounded Eviction Chains & Fingerprint Removal
- Target Module:
index.js(CuckooFilter.insert / CuckooFilter.delete) - Engineering Specification: Implement
insert(item)anddelete(item)onCuckooFilter. 1. Ininsert: placefpinbuckets[i1]orbuckets[i2]if space exists; otherwise loop up tomaxKickstimes swappingcurFpwith a slot inbuckets[idx]and jumping toidx = _altIndex(idx, curFp). 2. Indelete: remove one matchingfpfrombuckets[i1]orbuckets[i2]. - Verification Invariant: inserts with Cuckoo displacement and deletes without false negatives
Asymptotic & Memory Layout Guarantees
- Category: Hashing & Sketches
- Difficulty: Advanced (~35 minutes)
- Key Architectural Highlights:
• Kirsch-Mitzenmacher double-hashing Bloom filter with Uint32Array bitset
• Partial-key Cuckoo filter computing alternate bucket via i2 = i1 ^ hash(fp)
• Dynamic deletion support with zero false negatives and bounded kick-out displacement - Tags & Primitives:
Bloom Filter,Cuckoo Filter,Kirsch-Mitzenmacher,XOR Partial-Key Cuckoo,Probabilistic Sketch
Production Systems Context & Verification
This from-scratch implementation is engineered with zero external dependencies and deterministic verification harnesses. Every internal invariant—from pointer restoration and bitmask addressing to amortized potential bounds and tree height balance—is asserted directly in test.js. Use the interactive browser workbench above to complete the guided steps in Guided Lab mode or inspect and benchmark the complete reference architecture in Full Solution mode.