The Power of Hashing with Mersenne Primes

Thomas Dybdahl Ahle, Jakob Tejs Bæk Knudsen, Mikkel Thorup
8/19/2020
cs.DS

Official code: thomasahle/mersenne (4 stars, TeX, last commit 2021-08-27).

Abstract

The classic way of computing a $k$-universal hash function is to use a random degree-$(k-1)$ polynomial over a prime field $\mathbb Z_p$. For a fast computation of the polynomial, the prime $p$ is often chosen as a Mersenne prime $p=2^b-1$.

Show full abstract

In this paper, we show that there are other nice advantages to using Mersenne primes. Our view is that the hash function's output is a $b$-bit integer that is uniformly distributed in $\{0, \dots, 2^b-1\}$, except that $p$ (the all \texttt1s value in binary) is missing. Uniform bit strings have many nice properties, such as splitting into substrings which gives us two or more hash functions for the cost of one, while preserving strong theoretical qualities. We call this trick "Two for one" hashing, and we demonstrate it on 4-universal hashing in the classic Count Sketch algorithm for second-moment estimation. We also provide a new fast branch-free code for division and modulus with Mersenne primes. Contrasting our analytic work, this code generalizes to any Pseudo-Mersenne primes $p=2^b-c$ for small $c$.

View on arXivView PDF

Code Implementations(1)

40TeX, C++Jul 31, 20205 years ago

Similar Papers

Cite this paper

@article{ahle2020power,
  title  = {The Power of Hashing with Mersenne Primes},
  author = {Thomas Dybdahl Ahle and Jakob Tejs Bæk Knudsen and Mikkel Thorup},
  year   = {2020},
  eprint = {2008.08654},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2008.08654}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2008.08654.svg)](https://codeofpaper.com/paper/2008.08654)

Discussion