Bipartite ShockHash: Pruning ShockHash Search for Efficient Perfect Hashing

  • Author(s):

    Hans-Peter Lehmann, Peter Sanders, Stefan Walzer

  • Source:


  • Date: October 2023
  • A minimal perfect hash function (MPHF) maps a set of n keys to the first n integers without collisions. Representing this bijection needs at least log2(e)≈1.443 bits per key, and there is a wide range of practical implementations achieving about 2 bits per key. Minimal perfect hashing is a key ingredient in many compact data structures such as updatable retrieval data structures and approximate membership data structures.
    A simple implementation reaching the space lower bound is to sample random hash functions using brute-force, which needs about e^n≈2.718^n tries in expectation. ShockHash recently reduced that to about (e/2)^n≈1.359^n tries in expectation by sampling random graphs. With bipartite ShockHash, we now sample random bipartite graphs. In this paper, we describe the general algorithmic ideas of bipartite ShockHash and give an experimental evaluation. The key insight is that we can try all combinations of two hash functions, each mapping into one half of the output range. This reduces the number of sampled hash functions to only about (√(e/2))^n≈1.166^n in expectation. In itself, this does not reduce the asymptotic running time much because all combinations still need to be tested. However, by filtering the candidates before combining them, we can reduce this to less than 1.175^n combinations in expectation.
    Our implementation of bipartite ShockHash is up to 3 orders of magnitude faster than original ShockHash. Inside the RecSplit framework, bipartite ShockHash-RS enables significantly larger base cases, leading to a construction that is, depending on the allotted space budget, up to 20 times faster. In our most extreme configuration, ShockHash-RS can build an MPHF for 10 million keys with 1.489 bits per key (within 3.3% of the lower bound) in about half an hour, pushing the limits of what is possible.