Inferensys

Glossary

Cuckoo Hashing

Cuckoo hashing is a collision resolution scheme that uses two or more hash functions to map each key to multiple candidate positions, relocating existing keys to guarantee worst-case constant-time lookups and efficient storage in hash tables.
Strategy consultant facilitating AI use case discovery workshop, sticky notes on glass wall, casual corporate meeting.
COLLISION RESOLUTION

What is Cuckoo Hashing?

A hashing scheme that resolves collisions by relocating existing keys using multiple hash functions, commonly used in PSI protocols to optimize storage and reduce communication complexity.

Cuckoo hashing is a collision resolution technique that guarantees worst-case constant lookup time by using two hash functions to place each key in one of two possible buckets. When a collision occurs, the existing key is evicted and rehashed to its alternate location, potentially displacing another key in a cascading process until all keys find a stable position or the table is rehashed.

In private set intersection protocols, cuckoo hashing maps elements into bins to reduce the number of comparisons required, enabling sublinear communication complexity. The KKRT protocol leverages this structure to achieve highly efficient semi-honest PSI by ensuring each bin contains at most one element, allowing the use of oblivious transfer instead of more expensive circuit-based comparisons.

ALGORITHMIC FOUNDATIONS

Key Features of Cuckoo Hashing

Cuckoo hashing is a collision resolution strategy offering worst-case constant-time lookups and efficient use of memory, making it a critical building block for high-performance Private Set Intersection (PSI) protocols.

01

Two-Table Architecture

Cuckoo hashing maintains two separate hash tables, each with its own independent hash function. An element x can only reside in one of two possible locations: Table 1 at index h1(x) or Table 2 at index h2(x). This deterministic placement guarantees that lookups require checking at most two positions, achieving worst-case O(1) constant-time retrieval.

02

The Eviction Mechanism

When inserting an element x and both candidate slots are occupied, the algorithm evicts the existing occupant and re-inserts it using its alternate hash function. This triggers a chain of relocations:

  • Evicted element y moves to its alternate slot
  • If that slot is occupied, z is evicted and re-inserted
  • The process continues until a vacant slot is found

This cascading behavior is the origin of the name, inspired by the brood parasitism of cuckoo birds that evict other eggs from nests.

03

Cycle Detection and Rehashing

An insertion sequence can enter an infinite loop where evictions cycle through the same set of occupied slots. To handle this, implementations enforce a maximum eviction threshold (typically O(log n)). If the threshold is exceeded, the entire data structure is rebuilt from scratch using two new randomly selected hash functions. This rehashing operation is amortized over many insertions, preserving expected constant-time insertion performance.

04

Space Efficiency and Load Factor

With two tables of size (1+ε)n each, Cuckoo hashing achieves a load factor exceeding 95% while maintaining constant-time operations. The space overhead is tunable:

  • Higher ε reduces insertion failures and rehash frequency
  • Lower ε maximizes memory utilization
  • Practical PSI implementations often use ε ≈ 0.2 to 0.4 to balance speed and space

This efficiency is critical for PSI protocols where hash tables must fit within tightly constrained communication budgets.

05

Role in Private Set Intersection

Cuckoo hashing is a core component of modern PSI protocols like KKRT and PSZ. It enables efficient oblivious transfer (OT)-based membership testing:

  • The sender inserts their set into a Cuckoo table
  • The receiver uses OT to probe specific table positions without revealing which element they are querying
  • The deterministic two-slot placement ensures each receiver element requires only a small, fixed number of OT operations

This reduces communication complexity from linear to sublinear in the sender's set size.

06

Cuckoo Hashing Variants

Several optimized variants extend the basic scheme:

  • d-ary Cuckoo Hashing: Uses d > 2 hash functions and tables, reducing eviction chains at the cost of more lookup probes
  • Cuckoo Hashing with a Stash: A small auxiliary storage for elements that fail to insert, eliminating rehashing entirely at the cost of a bounded stash size
  • Bucketized Cuckoo Hashing: Each table slot holds a small bucket of b elements, improving load factor and reducing insertion failures

Bucketized variants are particularly popular in PSI for their cache-friendly memory access patterns.

CUCKOO HASHING IN PSI

Frequently Asked Questions

Explore the mechanics and cryptographic role of Cuckoo Hashing, a pivotal data structure for optimizing storage and slashing communication complexity in modern Private Set Intersection protocols.

Cuckoo Hashing is a collision resolution scheme that achieves worst-case constant lookup time by using two (or more) distinct hash functions to map each key to two possible buckets. When inserting a new key x, if its primary bucket is occupied, the existing key is evicted and relocated to its own alternative bucket. This cascading eviction process continues until a vacant slot is found or a cycle is detected, triggering a rehash. This guarantees that every key resides in one of its two designated positions, eliminating linear probing chains and ensuring deterministic O(1) retrieval performance.

HASH TABLE COLLISION STRATEGIES

Cuckoo Hashing vs. Other Collision Resolution Schemes

Comparison of Cuckoo Hashing against chaining, linear probing, and double hashing across key performance and security dimensions relevant to PSI protocols.

FeatureCuckoo HashingChainingLinear ProbingDouble Hashing

Worst-case lookup time

O(1) - exactly 2 probes

O(n) - list traversal

O(n) - cluster scan

O(n) - probe sequence

Average load factor achievable

Up to 50% (2 functions)

90%+

70-80%

70-80%

Insertion determinism

Memory overhead per slot

None (in-place)

Pointer per node (8 bytes)

None (in-place)

None (in-place)

Cache locality

Good (2 random accesses)

Poor (pointer chasing)

Excellent (sequential)

Moderate (strided)

Deletion complexity

O(1) worst-case

O(1) average

Complex (tombstones)

Complex (tombstones)

Resistant to timing side-channels

Suitable for circuit-based PSI

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.