arXiv:2610.17833cs.DSOct 2026

Manuscript Offprint

arXiv:2610.17833

PHastR: Faster Minimal Perfect Hashing with Rotated Layouts

Sebastiano Vigna

Abstract

We present PHastR, a minimal perfect hash function of the PHast family. Like PHast +^{+}, the fast-to-build variant of PHast, PHastR finds feasible seeds with bit-parallel operations: its seeds move keys along rings of slots, and to evaluate the seeds of a bucket it cyclically shifts, for each key, a word recording which slots of its ring are used. Unlike PHast +^{+}, however, it is almost immune to self-collisions, which make two keys of a bucket collide for (almost) all its seeds: more than a third of the buckets bumped by PHast +^{+} with wrapping and multiplier 3 contain one. With 8-bit seeds, PHastR uses 1.94 bits per key, essentially the same space as the best variant of PHast +^{+} with wrapping, but it is built in 37% of the time, and its queries are 28% faster on 10910^{9} keys, as it bumps 0.5% of the keys instead of 3.9%; they are faster also than those of PHast, which takes twelve times as long to build, and about as fast as those of PtrHash, which uses more than one bit per key more. With a larger expected bucket size PHastR comes within 0.02 bits per key of the space of PHast, using 1.90 bits per key, and still has faster queries. Its construction also scales better with the number of threads: with all the threads of a 48-core machine it is almost three times faster than that of PHast +^{+}. Finally, we argue that when each key can be placed only within a range of W slots, every placement of n random keys on n slots, however found, must bump on large key sets a constant fraction of the keys: we derive a lower bound of about 0.1/W on this fraction, and we estimate that the best placement bumps about 1/2W of the keys, which is about one tenth of the keys bumped by PHastR.

1 Introduction

A minimal perfect hash function (MPHF) maps a static set of nn keys bijectively to [0..n)[0..n); it requires at least lg⁡e≈1.443\lg e \approx 1.443 bits per key [14] (we use lg⁡\lg for the binary logarithm and ln⁡\ln for the natural logarithm). Among the many practical constructions, bucket placement gives the fastest queries: keys are hashed to buckets, and a per-bucket seed chooses for each key of the bucket a slot of [0..n)[0..n), so that no two keys collide. The idea goes back to FCH [13] and to Pagh's hash-and-displace [28], and it has been refined by many constructions since (Section 2). The main goal of these constructions is not to approach the lower bound, as those based on recursive splitting do at the price of slower queries, but to obtain a practical structure that answers a query with close to one memory access on average.

PHast [4, 5] pushes this approach to its limit: the seeds are stored in a plain array of fixed-width values, each seed places the keys of its bucket inside small overlapping slices of the output range, and a query reads a single seed for almost all keys. Finding the seeds, however, is expensive, as PHast tries all the seeds of each bucket: construction takes hundreds of nanoseconds per key. Its variant PHast +^{+} finds feasible seeds with bit-parallel operations, and it is an order of magnitude faster to build, but with 8-bit seeds it needs 2.115 bits per key instead of 1.885. Its variants with wrapping, in which keys wrap around the end of their slices, need less space (1.939 bits per key for the best one, that is, the one using the least space), but they are slower to build.

In this paper we present PHastR, a structure of the same family that, with 8-bit seeds, has almost the space of PHast, faster queries, and a construction faster than that of PHast +^{+}, especially with several threads.

The idea behind PHastR lies between PHast and PHast +^{+}. In PHast +^{+} a seed moves all the keys of a bucket by the same amount: this makes it possible to evaluate many seeds at once with bit-parallel operations, but two keys of a bucket that collide for one seed collide for (almost) all seeds. In PHast, instead, each seed places the keys independently, but seeds must be tried one at a time. In PHastR the lowest bits of a seed choose one of a few independent layouts, each assigning an offset to every key, and the remaining bits choose a rotation, which moves all the keys of the bucket by the same amount along their rings of slots: all the rotations of a layout can be evaluated at once, as in PHast +^{+}, but two keys collide for (almost) all seeds only if they do so in every layout, which is very unlikely. Thus, PHastR bumps far fewer keys than PHast +^{+}, and since, once the seed width and the expected bucket size are fixed, bumping is where both the excess space and the slow queries come from, it gets almost the space of PHast with faster queries; choosing a layout requires just two shifts.

This paper makes four contributions:

  • PHastR and its bit-parallel search, which finds all the rotations of a layout that map no key to a used slot by cyclically shifting, for each key, the bits recording which slots of its ring are used (Section 3);

  • a comparison with PHast and PHast +^{+}, showing that a large part of the bumping of PHast +^{+} is caused by self-collisions inherent to its additive scheme, and that layouts make their effect negligible (Section 4);

  • an implementation in the Rust crate sux 1^{1}, an experimental comparison with the reference implementation of PHast and PHast +^{+} and with PtrHash (Section 5), and an offline construction that reads the keys just once, needs on large key sets less than half a byte per key of memory, and builds the same structure as the construction in memory (Section 6);

  • an analysis of the number of keys that every placement must bump when each key can be placed only within a range of W slots: on large key sets we derive a lower bound of about 0.1/W on the fraction of bumped keys, and we estimate that the best placement bumps about 1/2W of the keys, so no search can produce a first level free of bumping, but PHastR bumps about ten times as many keys as this constraint forces (Section 7).