Locally Uniform Hashing

Ioana O. Bercea, Lorenzo Beretta, Jonas Klausen, Jakob Bæk Tejs Houen, Mikkel Thorup · OpenReview

Abstract

In computer science theory, many fundamental algorithms are analyzed under the assumption of access to a "fully random" hash function. However, implementing such functions is practically impossible due to astronomical memory requirements. Practitioners often settle for fast but theoretically weak hash functions that can fail on structured data. This paper introduces Tornado Tabulation Hashing, a novel approach that provides strong theoretical guarantees—behaving almost identically to fully random functions for key algorithms like linear probing—while maintaining the high-speed performance required for modern data streams.

Introduction

The efficiency of many randomized algorithms, such as linear probing for hash tables or HyperLogLog for cardinality estimation, relies on the assumption that hash values are distributed uniformly and independently. In practice, however, we use hash functions that are far from fully random. Standard implementations, such as linear hashing (2-independent), are computationally efficient but possess a significant "dark side": they can fail spectacularly when processing structured data, such as arithmetic sequences or dense sets. In these scenarios, performance can degrade from constant time to logarithmic time, creating bottlenecks in high-performance systems.

Previous attempts to bridge this gap, such as "mixed tabulation," offered theoretical bounds that only became meaningful for impractical character sizes. Tornado Tabulation Hashing addresses this by providing "unconditional" guarantees that hold even for the small 8-bit characters typical of modern CPU caches.

The Tornado Tabulation Method

Tornado Tabulation Hashing builds upon the foundation of simple tabulation. In simple tabulation, an input key is divided into several characters (e.g., a 32-bit key split into four 8-bit characters). Each character serves as an index for a lookup table containing random values, and the results are combined using the XOR operation.

The "Tornado" innovation introduces a cascading dependency structure known as The Twist. Instead of treating each character independently, the algorithm progressively defines derived characters. Each subsequent character in the sequence is a hash of all preceding characters. This cascading effect systematically breaks linear dependencies between input keys, ensuring that even highly structured inputs are effectively randomized.

Local Uniformity

A central contribution of this work is the formalization of Local Uniformity. The authors prove that Tornado Tabulation ensures that for any small subset of keys—specifically those that an algorithm interacts with simultaneously, such as keys hashing to the same neighborhood in a hash table—the hash values behave as if they were generated by a perfectly random function. This property allows developers to use Tornado hashing as a drop-in replacement for fully random functions in a wide array of algorithms.

Implementation and Efficiency

Despite its strong theoretical underpinnings, the implementation of Tornado Tabulation is remarkably simple. The algorithm utilizes basic bitwise shifts, XOR operations, and table lookups, making it highly compatible with modern CPU architectures.

For scenarios requiring randomness over exceptionally large sets of keys, the authors propose Tornado-Mix. This hybrid version utilizes a small number of larger tables outside the primary L1/L2 cache to maintain independence without significantly sacrificing throughput. The C implementation of Tornado hashing is highly competitive, matching the speed of degree-2 polynomials, which are currently considered the gold standard for fast, reasonably strong hashing.

Key Results and Performance

The paper demonstrates the effectiveness of Tornado Tabulation through several rigorous metrics:

  • Linear Probing: The authors prove that Tornado hashing yields an expected probe length of $(1 + o(1))(1 + 1/\epsilon^2)/2$. This matches the classic 1963 analysis by Donald Knuth for fully random hashing, confirming that Tornado hashing is provably optimal for hash table implementations.
  • Independence on Fixed Sets: For any fixed set of $n$ keys, if $n$ is less than or equal to half the alphabet size (e.g., $n \le 128$ for 8-bit characters), the resulting hash values are completely independent with very high probability.
  • The Splitting Trick: The method provides a more efficient implementation of the "splitting trick" used to construct complex data structures like succinct dictionaries. This reduces both space and time overhead compared to previous methods that relied on Siegel’s highly independent hashing.

Conclusion and Future Work

Tornado Tabulation Hashing provides a practical and theoretically sound solution to the long-standing discrepancy between hash function theory and practice. By breaking the "exponential curse" of previous schemes, it offers meaningful error bounds for the table sizes actually used in production environments.

While the implementation is straightforward, the mathematical proof of local uniformity is complex. Future research may explore the broader class of algorithms that can benefit from local uniformity and investigate how varying CPU architectures—specifically the trade-off between multiplication costs and table lookup speeds—affect the optimal choice of hash function parameters. For now, Tornado Tabulation stands as a robust bridge between the ideal of full randomness and the necessity of high-speed computation.

Summary updated

BibTeX
@inproceedings{bercea2023locally,
  author = {Ioana O. Bercea and Lorenzo Beretta and Jonas Klausen and Jakob Bæk Tejs Houen and Mikkel Thorup},
  title = {{Locally Uniform Hashing}},
  booktitle = {FOCS},
  year = {2023},
  url = {https://openreview.net/forum?id=fRvekzW0eS},
}
Figure