Skip to main content
QUICK REVIEW

[Paper Review] High Speed Hashing for Integers and Strings

Mikkel Thorup|arXiv (Cornell University)|Apr 26, 2015
Algorithms and Data CompressionComputer Science11 references19 citations
TL;DR

This paper presents highly efficient, practical hash functions for integers and variable-length strings, leveraging multiply-shift and polynomial hashing over Mersenne primes. It achieves near-optimal speed—up to an order of magnitude faster than textbook methods—while maintaining strong theoretical guarantees like strong universality, making it ideal for real-world applications in hash tables and string signatures.

ABSTRACT

These notes describe the most efficient hash functions currently known for hashing integers and strings. These modern hash functions are often an order of magnitude faster than those presented in standard text books. They are also simpler to implement, and hence a clear win in practice, but their analysis is harder. Some of the most practical hash functions have only appeared in theory papers, and some of them requires combining results from different theory papers. The goal here is to combine the information in lecture-style notes that can be used by theoreticians and practitioners alike, thus making these practical fruits of theory more widely accessible.

Motivation & Objective

  • To bridge the gap between theoretical hash function design and practical implementation by synthesizing results from multiple theory papers into accessible, efficient constructions.
  • To develop hash functions that are significantly faster than textbook implementations while preserving strong theoretical properties such as universality and low collision probability.
  • To enable efficient, high-performance hashing for both fixed-size integers and variable-length strings, particularly in applications like hash tables and string signatures.
  • To address the performance bottleneck in existing string hashing methods by introducing a two-stage approach: chunking followed by fast hashing of compressed chunks.
  • To explore whether simple, fast methods like multiply-shift can be adapted directly to strings without relying on complex algebraic structures like prime fields.

Proposed method

  • Uses multiply-shift hashing for 64-bit integers via a single 64-bit multiplication and bit shift, achieving strong universality with minimal computation.
  • Employs polynomial hashing over Mersenne primes (e.g., $2^{89}-1$) for variable-length strings, using coefficients $a$, $b$, and $c$ to compute $h_{a,b,c}(\vec{x}) = (a \cdot \vec{x} + b) \bmod p$ with $c$ as a constant offset.
  • Introduces a two-stage hashing pipeline: first compress variable-length strings into shorter 64-bit values using a fast, strongly universal function $r$, then apply the slow but secure Mersenne prime-based hash to the compressed sequence.
  • Applies the signature idea from universal hashing: map complex keys to a smaller integer domain $[u]$ via a collision-free hash, then apply $k$-independent hashing on the reduced domain.
  • Uses the union bound to analyze collision probabilities, showing that the probability of collision between two distinct strings of length $\leq p/m$ is at most $2/m$, making the function 2-approximately universal.
  • Proposes a hybrid strategy: use fast, bounded-length hashing for short strings (e.g., up to 32 64-bit words), and fall back to the generic variable-length scheme for longer strings to optimize performance.

Experimental results

Research questions

  • RQ1Can we design hash functions for integers and strings that are both highly efficient in practice and provably secure under strong universality?
  • RQ2How can we achieve a significant speedup in string hashing without sacrificing collision resistance, especially for long strings?
  • RQ3Is it possible to use simple, fast operations like multiply-shift directly on strings, bypassing complex modular arithmetic over prime fields?
  • RQ4What is the optimal trade-off between speed and collision probability when hashing variable-length strings using a two-stage compression and hashing approach?
  • RQ5Can we extend the use of $k$-independent hashing to complex data structures like variable-length strings through universe reduction and signature hashing?

Key findings

  • The multiply-shift method for 64-bit integers achieves strong universality with only one multiplication and one shift, making it up to an order of magnitude faster than textbook methods.
  • Polynomial hashing over Mersenne primes ensures that the collision probability between any two distinct strings of length at most $p/m$ is at most $2/m$, making the function 2-approximately universal.
  • By compressing strings into shorter 64-bit values using a fast, strongly universal function $r$, the overall hashing speed is dramatically improved, as the expensive Mersenne prime arithmetic is applied only to short sequences.
  • The two-stage approach reduces the effective input length by a factor of 32, significantly lowering the computational cost while adding only a small, bounded increase in collision probability.
  • For strings of length up to $d$ (e.g., 32 words), using a dedicated fast hashing scheme is more efficient than the generic variable-length method, justifying a hybrid implementation strategy.
  • The paper demonstrates that universe reduction via collision-free hashing to a smaller domain $[u]$ enables the use of $k$-independent hashing on complex keys, with the overall function remaining $k$-independent on any bounded set of keys.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.