Manuscript Offprint
arXiv:2610.17833PHastR: Faster Minimal Perfect Hashing with Rotated Layouts
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 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 keys bijectively to ; it requires at least bits per key [14] (we use for the binary logarithm and 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 , 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 , 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).
Bucket placement goes back to FCH [13], which, however, was slow to build unless its functions used a lot of space, and to Pagh's hash-and-displace [28], in which each bucket stores a displacement that moves all its keys by the same amount: two keys of a bucket that collide for one displacement thus collide for all of them, and the scheme requires the pair of hash functions locating the keys to be injective on the key set. CHD [1] brought the idea back: the seed of a bucket selects a function from a family of random functions (in practice, linear combinations of two hash functions of the key with coefficients depending on the seed), so that, in the analysis, different seeds place the keys of a bucket independently; seeds are tried one at a time, in order,
https://crates.io/crates/sux and then compressed. PTHash [29] revisited FCH with a careful engineering of the encoding of the seeds (its pilots) and of the distribution of the keys into buckets; it was followed by PHOBIC [19], which optimizes the bucket sizes and interleaves the encoding of the pilots, and by PtrHash [17], which stores the pilots in bytes and replaces the greedy placement of the buckets with a cuckoo-like search that evicts already placed buckets, obtaining very fast queries. Finally, PHast [4, 5] combines fixed-width seeds and slices with bumping: buckets that cannot be placed are left to the following levels, so that the search never backtracks.
PHastR inherits the structure of PHast, and its seeds lie between two extremes: the additive displacements of hash-and-displace and PHast , and the independent functions of PHast and of the analysis of CHD. Like the linear combinations used in practice by CHD, a seed both changes the relative positions of the keys of a bucket (by choosing a layout) and moves them all by the same amount (by choosing a rotation), but the few layouts are obtained for free from the computation of the bucket, and all the rotations of a layout are evaluated at once with bit-parallel operations.
3 PHastR
PHastR follows the scheme of PHast [4, 5]; we discuss the differences in Section 4. Each key has a 64-bit hash, which determines its bucket, among B buckets, and its slice, an interval of L consecutive slots of the output range whose start grows linearly with the hash. Each bucket has a seed, stored in a plain array of S-bit values; the seed maps each key of the bucket to a slot of its slice. A slot is used if a key has already been mapped to it, and free otherwise; a seed is feasible for a bucket if it maps its keys to distinct free slots.
The structure is a sequence of levels using the same scheme: buckets for which no seed is feasible are bumped (seed 0), and their keys are handled by the following levels. The first level has m = n, so every bumped key leaves a free slot (a hole) in the first level, and an Elias–Fano sequence [10, 12, 32], the remapping, maps the slots of the following levels, in order, to the holes. Since bumped keys are few, a query reads a single seed for almost all keys. Seeds are assigned by a sweep over the buckets: buckets enter, in order of index, the window, a priority queue that favors large buckets and holds the buckets not yet placed among the 256 starting from the first bucket not yet placed; the sweep repeatedly extracts the bucket of highest priority and gives it the feasible seed minimizing the product of the distances of the slots of its keys from a point slightly before the slices of the bucket.
Each hole costs about bits in the remapping, where is the fraction of bumped keys, and the bumped keys must be placed again by the following levels, which in turn bump a fraction of their keys, so that overall the levels receive about keys. With S-bit seeds and expected bucket size the seeds take bits for each key a level receives, and the space in bits per key is thus approximately
and since the entropy of a random set of holes is already about , the encoding of holes cannot be substantially improved: once and are fixed, the only lever is . We will show in Section 7 that on large key sets no placement, however found, can avoid bumping altogether; the purpose of the design of PHastR is to bump few keys while finding feasible seeds with bit-parallel operations.
Placement scheme. We denote with and the upper and lower 64 bits of a 128-bit product. Consider a level with output range and buckets, whose slices have length (slice lengths are powers of two; we discuss their choice below). Let be the hash of a key, and let . The bucket of the key is , which in fixed-point arithmetic buckets whose keys can reach slot p

Figure 1: Buckets, slices and strides in a level with output range , , expected bucket size , slices of length , and stride . The top line shows some consecutive buckets, the middle line the slots of the output range, and the bars at the bottom the slices of the keys , , of bucket (gray). As both the bucket of a key and the start of its slice grow linearly with its hash, each bucket corresponds to an interval of about slice starts (the dashed lines delimit that of bucket ), and the slices of the keys of bucket start a few slots apart. In a layout, a key moves along its ring, the slots of its slice whose distance from its base slot (circled) is a multiple of (the dots, for ). The seed of bucket is chosen using the distances of the slots of its keys from its origin, which precedes its leftmost slice (95 slots before in our implementation). Only the keys of the about buckets whose slices can contain a slot (gray) can be placed in it.
is just hi(hB), and the start of its slice is , which is hi(h(m - L + 1)), so that slices lie within the output range (Figure 1). Moreover, there are layouts, where is a power of two, each assigning an in-slice offset to every key: letting , we divide into fields of bits, and layout assigns to the key the offset
that is, the lowest bits of field . We require , so that the offsets of different layouts use disjoint bits of .
The seed of a bucket has two parts: its lowest bits, , choose a layout, and its remaining bits, , a rotation. Assuming for the time being that , let : the seed maps each key of the bucket to the slot
where is the stride; the two forms are equal because , and queries compute the first one.
In words: once the layout is chosen, each key of the bucket has a base slot, the slot for rotation 0 (as offsets are uniform, the constant ru is immaterial), and rotation j moves all the keys of the bucket by jT slots, wrapping around the end of their slices. As the rotation varies, a key goes exactly once through the slots of its slice whose distance from its base slot is a multiple of T: we call these slots its ring in layout r (Figure 2). Seed 0, that is, layout 0 with rotation 0, marks bumped buckets, so layout 0 has one rotation less.
Two keys of a bucket with the same base slot in a layout move together, so they collide for all rotations but the few for which exactly one of them wraps around (the slices of the keys of a bucket can start a few slots apart): this is a self-collision. Since the offsets of different layouts use disjoint bits of o, self-collisions happen independently in each layout: a bucket of size k has a self-collision in every layout with probability about , which is negligible already for R = 2. Moreover, the seeds of a layout move all the keys of the bucket by the same amount, so they are strongly correlated, whereas seeds of different layouts are (almost) independent.
The assignment of buckets by a fixed-point multiplication, which makes each bucket an interval of hashes, was introduced by Genuzio, Ottaviano and Vigna for the offline bucketing of GOV [15].

Figure 2: The slots of the three keys , , of a bucket for each seed, with 3-bit seeds, R = 2 layouts, and slices of length L = 16 (for simplicity, the three slices coincide). Each of the top three lines shows the slice of a key, with the positions of some slots above, and a circle containing a seed s marks the slot to which s maps the key. Even seeds (gray circles) choose layout 0, odd seeds (white circles) layout 1: seed chooses layout r and rotation j, which moves the keys by jT slots from their base slots, where T = 4 is the stride, so in each layout a key goes through the four slots of its ring (only three of them in layout 0, as seed 0 is not available). In layout 0 the keys and have the same base slot, so they collide for all even seeds; in layout 1 they do not. The bottom line shows the slots that are already used (gray): the only feasible seed is 5, which maps the keys to the free slots marked in red.
The value costs nothing, as it is the other half of the product that yields the bucket, and it is a good source of offsets: for the keys of bucket we have , so is the fractional part of , which is uniformly distributed if is. Moreover, the offsets of the keys of a bucket are independent of each other for every layout, which would not be true of offsets taken from the upper bits of , as the keys of a bucket share the upper bits of .
We require the number B of buckets to be odd: if B is even, the lowest bit of o, and thus of the offset of layout 0, is always zero, whereas if B is odd the lowest bits of o are a bijective function of the lowest bits of h.
Queries. A query computes , reads the seed of bucket , and, unless , computes the first form of the formula above. There is no need to extract : since , we have , and the query computes
where a single reduction modulo both extracts the offset from the shifted and wraps the sum around the end of the slice.
Search. In a bit vector marking the used slots, the bits of the slots of a ring would be T bits apart. We make them adjacent by storing the set of used slots by residue classes modulo T, as suggested by Beling and Sanders for PHast with wrapping [4, 5], that is, as T rows in which bit q of row records whether slot is used. All the slots of a ring have the same residue modulo T (wrapping around the end of a slice does not change it, as T divides L), so the bits of the ring of a key, which record whether the slots of its ring are used, are L/T consecutive bits of a row. We number the slots of a ring from 0 in order of position in the slice, and we call ring position of a key the number y of its base slot: rotation j maps the key to slot of its ring. Thus, cyclically shifting the bits of the ring so that bit y becomes bit 0, we obtain L/T bits whose bit j tells whether rotation j maps the key to a used slot, and combining them for all the keys of the bucket by a bitwise OR we obtain L/T bits whose zeros are the free rotations, which map every key to a free slot (Figure 3). A free rotation j yields the feasible seed unless two keys of the bucket are mapped to the same slot, which is rare. For S = 8 and R = 4 a
(a)
(b)


Figure 3: Finding the free rotations of layout 1 for the bucket of Figure 2. (a) The set of used slots of Figure 2 is stored by residue classes modulo the stride T = 4: bit q of row records whether slot is used (the labels on the right list the slots of each row). (b) The bits of the ring of a key form a row of (a) (in general, L/T consecutive bits of a row), and the rotations go through them cyclically, starting from the ring position of the key: for example, the base slot of is slot 15 (seed 1), which is slot 3 of its ring (row 3), so the ring position of is 3. Each line shows the bits of the ring of a key cyclically shifted by its ring position (the labels on the right give the row and the shift), so that column j corresponds to rotation j, that is, to seed . These bits are combined by a bitwise OR: the zeros of the result are the free rotations (here, only rotation 2, that is, seed 5, in red).
ring has slots whatever the slice length, except on small levels (see below), so its bits fill a word: each layout requires just reading and cyclically shifting a word for each key.
Among the free rotations of all layouts we choose, as does the current version of the reference implementation of PHast [3], the one minimizing the product of the distances of the slots of the keys from the origin of the bucket, which lies 95 slots before the start of the leftmost slice that a key of the bucket can have (Figure 1). We compute the logarithm of the product, that is, the sum of the base-2 logarithms of the distances, which we read, in fixed point with 24 fractional bits, from a table: since it is a sum of integers, the cost of a rotation does not depend on the order of the keys, which will be essential for the offline construction of Section 6. Evaluating a free rotation thus requires a table lookup for each key of the bucket. Ties are broken in favor of the first layout and, within a layout, of the first rotation. When a bucket has at most 32 free rotations, which is the common case, we evaluate all of them, with a single loop over the free rotations of all layouts that contains no other branch. When there are more free rotations (e.g., at the beginning of a sweep) we use instead the fact that in a layout the cost increases with the rotation, except at the rotations at which some key wraps around: thus, for a bucket of size k we need to consider only the first free rotation and, for each key, the first free rotation not smaller than the one at which the key wraps around, that is, at most free rotations per layout. Finally, when marking the slots of the best free rotation as used we check that no two keys of the bucket are mapped to the same slot, and otherwise we move to the next best one.
Grouping and scheduling. The sweep needs the hashes of the keys of each bucket, but in no particular order, and we do not want to keep more than one copy of them. Thus, we group the buckets into at most 256 parts, each made of a power-of-two number of consecutive buckets, and the keys into batches of consecutive keys. A thread computes the hashes of the keys of a batch, and appends each hash to the region associated with the batch and with the part containing the bucket of the hash, recording the part in a byte: the hashes in a region are thus in the order of the keys. Regions are sized before computing the hashes, assuming that hashes are uniform, with a slack of six standard deviations: the few hashes that do not fit their region, if any, are kept separately.
A part is distributed into buckets only when a sweep needs it, into a buffer of the sweep (the part is distributed first into smaller parts that fit the cache, and then each smaller part into its buckets), so regions are never modified. After the sweep, the keys of bumped buckets, which must be passed to the next level, are found by walking again the keys of each batch in order: the byte of a key gives its part, its hash is the next unread hash of the region of the batch for that part, and a bit vector with a bit per bucket tells whether the bucket of the hash has been bumped. Since a batch reads up to 256 regions at the same time, too many sequential streams for the hardware prefetchers, the walk prefetches each region two cache lines ahead. Writing to at most 256 regions at a time and working on smaller parts of about 150 KB is efficient on all the machines we tested, and the grouping needs, besides the hashes, little more than a byte per key: in our experiments, the whole construction needs about 11 bytes per key, excluding the keys (Table 6).
The priority of a bucket has the same form as in PHast: a weight depending on the size of the bucket, minus 1024 times the index of the bucket. Since buckets enter the window in order of index, the buckets of each size in it are in order of index, and the bucket with the highest priority is the first bucket of some size. Thus, instead of a priority queue we keep a first-in first-out queue for each size (buckets with 64 keys or more, which are extremely rare, are kept in a heap): extracting the next bucket requires scanning the first elements of a few queues, and adding a bucket takes constant time.
The set of used slots of the level, which is needed to build the remapping, is a byproduct of the sweep: the sweep keeps in a cyclic buffer only the bits of the slots that the buckets still to be placed can reach, and copies the bits of the slots that are no longer reachable to the bit vector of the level when their space in the buffer is recycled.
Slice length. The slice length of a level with output range is the smallest power of two larger than , up to a maximum, which is a parameter: we use for and for . The slices of small levels can thus have fewer slots than there are seeds, that is, : in this case we let , so the stride is , rings have slots (a single slot if ), and rotations and map the keys of a bucket to the same slots whenever divides .
Levels. The following levels use the same placement scheme with output range equal to their number of keys, and the remapping maps their slots to the holes of the first level. A bumped key is hashed again just once, with a different hash seed: if is this second hash, the hash of the key at level , which plays the role of at that level, is
is a salt associated with the level, and is a constant (we let ). Thus, the following levels depend only on and : once has been computed the key is no longer needed, and the code accessing the following levels, which takes just two integers, can be kept separate from that accessing the first level.
Colliding hashes. Keys with the same 64-bit hash at the first level have the same slice and the same offsets in all layouts, so they collide for every seed and their bucket is bumped; at the following levels their hashes depend also on the second hash, and thus they are separated. Since about pairs of keys have the same hash (about three for ), the keys bumped in this way are negligible with respect to the keys that are bumped anyway. Hence, 64-bit hashes are sufficient for any practical number of keys. Construction would fail only if two keys had the same pair of hashes, which happens in practice only for duplicate keys. Since duplicate keys are always bumped from the first level, to report them we examine the buckets of the second level: as two distinct keys might have the same hash at that level, keys of a bucket with the same hash are hashed again with a third hash seed, and only keys whose hashes coincide again are considered duplicates.
Last level. When at most 4096 keys are left, a last level with keys uses the same placement scheme with an output range of slots, expected bucket size , and no bumping, changing the salt (and, every eight attempts, enlarging the output range) in the unlikely case of failure.
Parallel construction. As in PHast, buckets are split into chunks (one for each thread, provided that each chunk has at least buckets, where g is the length of a gap) separated by gaps of
buckets: the slices of the keys of bucket start at about , and the slot of a key lies at most slots after the start of its slice, so (considering the rounding of slice starts) the keys of different chunks cannot reach the same slots (in Figure 1, the brace spans about as many buckets as a gap). Chunks are swept in parallel, and then all gaps are swept in parallel, each with a new sweep in which the slots used by the keys of the neighboring chunks (on both sides) are marked as used.
4 Differences from PHast and PHast
In PHast [4, 5], in its variant PHast , and in PHastR the bucket of a key with hash is , and the seed of the bucket maps the key to slot , where is the start of its slice: the three structures differ mainly in their placement scheme, that is, in the function . In PHast, is a pseudorandom function, so finding the best seed requires trying all seeds. PHast uses instead the additive scheme , so that feasible seeds can be found by combining, for each key, a word of the bit vector of used slots, but it needs more space than PHast; PHast with wrapping uses for a small multiplier , so that keys do not leave their slice, and needs less space than PHast without wrapping, but it is slower to build.
In PHastR, , where and . Within a layout the scheme of PHastR is thus additive, like that of PHast with wrapping, so the free rotations of a layout can be found with bit-parallel operations. In an additive scheme, however, two keys of a bucket that collide for one seed collide for (almost) all seeds: in the first level of the reference implementation of PHast with 8-bit seeds, wrapping, , and , on keys, 35% of the bumped buckets contain such a self-collision. In PHastR, instead, self-collisions happen independently in each layout, and buckets with a self-collision in every layout are negligible.
The construction of PHastR differs from that of the reference implementation also in several engineering aspects (Section 3): hashes are distributed into parts rather than sorted, the priority queue is replaced by a queue for each bucket size, bumped keys are hashed again just once rather than at each level, the last level uses the same scheme as the other levels rather than the pseudorandom scheme of PHast, and the gaps between the chunks of a parallel construction are swept in parallel, rather than serially. Slice lengths are those of PHast with wrapping, but the expected bucket size is smaller, and the weights of the bucket priorities are tuned for PHastR.
5 Experiments
We ran all timing experiments on an Amazon EC2 c7i.metal-24xl instance (one Intel Xeon Platinum 8488C with 48 cores, 105 MiB of L3 cache and 192 GiB of RAM), compiling with Rust 1.99 at optimization level 3, with thin link-time optimization, a single code-generation unit, and code generation for the native processor (-C target-cpu=native); the code of the experiments is available at https://github.com/vigna/phastr-bench. Keys are distinct 64-bit integers, obtained by multiplying their index by an odd constant and computing the exclusive or of the result with a fixed constant; to make query times comparable, all structures use the same hash function, GxHash with a hash seed. PHastR uses layouts, with byte seeds for and bit-packed seeds read without alignment for . Construction times include hashing; they are single-threaded unless otherwise noted, and they are medians of three constructions up to keys and of a single one on keys. Query times are medians over nine rounds of queries of consecutive keys of the set, and the rounds of the different structures are interleaved. Since all structures hash the key first, their memory accesses are random anyway: reading the keys in order avoids adding to every query the same cache miss on the array of keys.
We compare PHastR only with PHast, PHast , and PtrHash [17], the only structures in this region of the design space: in the extensive comparison of Beling and Sanders [4, 5], which also includes PTHash [29], PHOBIC [19], SicHash [23], and structures based on recursive splitting [6, 24] and on fingerprinting [2], they combine two to three bits per key with queries much faster than those of all the other structures.
The reference implementation of PHast and PHast is the ph crate by Beling [3], in the version of October 8, 2026 (commit aa497a8): we use Function2 with the seed choosers ShiftOnly for PHast , ShiftOnlyProdWrapped< > for PHast with wrapping, and SeedOnly(ProdOfValues) for PHast. The last two choose among the feasible seeds by the product of the distances of the slots, as PHastR does, whereas ShiftOnly takes the first feasible seed. We applied a fix to the parallel construction of ph (commit d0954d2 of the fork used for our experiments): without it, all threads but the first choose seeds using wrong bucket indices, and space grows with the number of threads; single-threaded constructions are not affected.
We also compare with PtrHash [17] (version 2.1.2), in its two minimal configurations: the default one, with expected bucket size , a linear assignment of keys to buckets, and a plain array for the remapping, and the compact one, with , a cubic assignment of keys to buckets approximating the optimal one of PHOBIC [19], and an Elias–Fano remapping. Both store pilots in bytes and use about 1.01n slots, so a small fraction of the keys must be remapped; the default configuration is built as a single part, and its construction is thus almost sequential, whereas the compact one is built in parallel parts. We measure the space of PtrHash as the space of its pilots and of its remapping.
Table 1 shows the results on keys, a size at which the structures fit in the cache. With 8-bit seeds and the suggested expected bucket size (we motivate this choice in Section 5.1), PHastR uses essentially the same space as the best variant of PHast with wrapping, that with , but it is built in 35% of the time, and its queries are 27% faster; with , PHast with wrapping uses 0.013 bits per key more, and it still takes 1.9 times as long to build. The queries of PHastR are 9% faster also than those of PHast, which takes almost fourteen times as long to build.
Queries are fast because PHastR bumps few keys: just 0.5% of the keys from the first level, against 4.2% and 3.9% for PHast with wrapping and and , respectively, and the 1.0% of PHast (with the same expected bucket size, however, PHast bumps fewer keys: 0.3% with ), and queries for bumped keys are much slower than the others. The expected bucket size thus trades space for query time: with PHastR bumps 1.2% of the keys, and it comes within 0.02 bits per key of the space of PHast, with slightly faster queries; with it bumps 2.3% of the keys, its space exceeds that of PHast by 0.013 bits per key, and its queries are slightly slower. With all three expected bucket sizes PHastR is also faster to build than PHast without wrapping.
PtrHash, in its default configuration, has queries almost as fast as those of PHastR with , but it uses more than one bit per key more, and it takes twice as long to build; its compact configuration uses 0.2 bits per key more than PHastR, and it is 3.5 times slower to build and 81% slower to query. With 10-bit seeds and PHastR uses less space than all
https://crates.io/crates/gxhash
Table 1: Comparison on keys (single-threaded construction).
| Method | Configuration | bits/key | build [ns/key] | query [ns] |
|---|---|---|---|---|
| 2.117 | 52 | 7.8 | ||
| wrap | 2.043 | 79 | 7.0 | |
| wrap | 2.001 | 81 | 6.1 | |
| wrap | 1.956 | 92 | 6.0 | |
| wrap | 1.943 | 116 | 5.9 | |
| wrap | 1.940 | 143 | 5.9 | |
| 1.887 | 682 | 4.7 | ||
| PtrHash | default, | 2.990 | 107 | 4.5 |
| PtrHash | compact, | 2.143 | 176 | 7.8 |
| 1.943 | 50 | 4.3 | ||
| 1.903 | 45 | 4.6 | ||
| 1.900 | 43 | 5.0 | ||
| 1.985 | 54 | 7.7 | ||
| wrap | 1.891 | 84 | 7.0 | |
| wrap | 1.851 | 114 | 6.7 | |
| wrap | 1.852 | 115 | 6.5 | |
| wrap | 1.842 | 164 | 6.5 | |
| wrap | 1.841 | 209 | 6.5 | |
| 1.814 | 2085 | 6.4 | ||
| 1.824 | 88 | 5.4 | ||
| 1.823 | 82 | 5.8 | ||
| 1.833 | 80 | 6.2 |
variants of , and it is built in 42% of the time of with wrapping and , and in 77% of the time of that with ; with it comes within 0.01 bits per key of the space of . In both cases its queries are faster than those of all the other structures with 10-bit seeds.
Table 2 shows that the picture does not change on keys: with 8-bit seeds and PHastR is built in 36% of the time of with wrapping and , and its queries are 22% faster; they are also 8% faster than those of , and 12% faster than those of PtrHash, which is built more than three times slower. With 8 threads PHastR is built in 36% of the time of with wrapping and when seeds have 8 bits, and in 43% of the time when they have 10 bits (with ); with 8-bit seeds it is built faster also than without wrapping, both with one thread (54 ns per key against 59) and with 8 threads (8.0 ns per key against 11.9). The default configuration of PtrHash, which is built as a single part, is barely faster to build with 8 threads (181 ns per key against 197).
5.1 Large Key Sets
Table 3 reports the results on keys. Space does not depend on the number of keys, and the ratios between the structures are similar to those of smaller key sets: with 8-bit seeds and , PHastR is built in 37% of the time of with wrapping and , and its queries are 28% faster. The exception is the default configuration of PtrHash: its construction falls further behind that of PHastR as the number of keys grows (with one thread it is 2.1, 3.6 and 6.7 times slower on , and keys, and with eight threads 11, 23 and 41 times slower), and its queries are now 3% faster than those of PHastR, at the price of more than one bit per key more. With 10-bit seeds and , PHastR uses less than 0.01 bits per key more than PHast, but it is built 23 times faster, and its queries are 8% faster. At this scale the cost of bumped keys becomes more visible, and we used it to choose the suggested expected bucket size.
(a) queries, keys

(b) construction, keys
(c) queries, keys
(d) construction, keys

(e) queries, keys
(f) construction, keys

Figure 4: Space versus query time (left) and single-threaded construction time (right) on , and keys (top to bottom) as the expected bucket size varies in steps of 0.25 around the configurations of Table 1: from 4 to 5 (PHastR), from 4.5 to 5.5 (PHast wrap ) and by 0.25 on each side (the others) with 8-bit seeds, and from 5.5 to 6.5 (PHastR and PHast wrap ) and by 0.25 on each side (the others) with 10-bit seeds; the configurations of each structure are joined in order of expected bucket size. PHast with wrapping is shown only with and , and the two configurations of PtrHash are single points; the space axis is broken at the dashed line, beyond which the default configuration of PtrHash, which uses 2.99 bits per key, is drawn. Each point is a configuration: lower and further to the left is better.
Table 2: Comparison on keys, with single-threaded and 8-threaded construction.
| Method | Configuration | bits/key | build [ns/key] | query [ns] | |
|---|---|---|---|---|---|
| 1 thread | 8 threads | ||||
| 2.116 | 59 | 11.9 | 16.2 | ||
| wrap | 1.955 | 99 | 16.5 | 13.4 | |
| wrap | 1.939 | 148 | 22.5 | 13.2 | |
| PHast | 1.885 | 688 | 89.9 | 11.2 | |
| PtrHash | default, | 2.990 | 197 | 181.4 | 11.7 |
| PtrHash | compact, | 2.143 | 180 | 24.3 | 18.0 |
| PHastR | 1.942 | 54 | 8.0 | 10.3 | |
| PHastR | 1.902 | 50 | 7.2 | 10.7 | |
| PHastR | 1.898 | 48 | 7.4 | 11.6 | |
| wrap | 1.847 | 121 | 19.1 | 14.6 | |
| wrap | 1.836 | 215 | 30.9 | 14.5 | |
| PHast | 1.810 | 2092 | 267.0 | 14.6 | |
| PHastR | 1.820 | 92 | 13.3 | 12.3 | |
| PHastR | 1.819 | 87 | 12.3 | 13.0 | |
Trade-offs. Figure 4 shows what happens when the expected bucket size varies around the configurations of the tables. Space has a minimum, query time grows with , as more keys are bumped, and construction time varies by at most , except for PHastR, whose construction becomes slower as decreases (by up to ). The curves of PHastR are slightly to the right of those of PHast (their minima differ by about 0.01 bits per key), but their construction times differ by more than a factor of ten, and the curves of PHastR are below those of PHast: at about the same space, PHastR has faster queries.
The curves of PHast with wrapping are to the right of both, even with . Considering the three dimensions at once, no configuration of PHast, with or without wrapping (also with , 2 and 5, which are not plotted), is Pareto-optimal: each is dominated by a configuration of PHastR with less space, faster queries and a faster construction. The only configurations that are not dominated, besides most of those of PHastR, are some of those of PHast, which win by 0.01–0.02 bits per key in space or by less than 1 ns in query time, at more than ten times the construction time, and, on keys, the default configuration of PtrHash, whose queries are 0.1 ns faster than those of the fastest configuration of PHastR, at the price of almost one bit per key more and almost six times the construction time.
Bumped keys. Table 4 shows the time of queries for the keys of the first level only, for four of the configurations of the previous tables. It is essentially the same for PHast with wrapping and for PHastR, and it grows with the number of keys, as the array of seeds becomes larger; it is slightly larger for the reference implementation of PHast, which explains part of its gap. Besides that, the differences between the structures are due to bumped keys. In a workload in which all keys are queried, a query for a bumped key takes about 25–50 ns more than a query for a key of the first level on keys, and about 170–180 ns more on keys: a bumped key reads the seed of another level, and then the remapping, whose accesses (the inventory of the selection structure, and then the upper bits of the Elias–Fano sequence) are dependent cache misses. Thus, each percent of bumped keys costs on average up to half a nanosecond per query on keys, and almost 2 ns on keys: the larger the key set, the more a small expected bucket size is convenient. This is the reason why we suggest (and, for the same reason, with 10-bit seeds): with PHastR uses 0.04 bits per key less, and it is built faster, but on keys its queries are 7% slower.
Table 3: Comparison on keys, with single-threaded and 8-threaded construction.
| Method | Configuration | bits/key | build [ns/key] | query [ns] | |
|---|---|---|---|---|---|
| 1 thread | 8 threads | ||||
| 2.115 | 65 | 12.5 | 32.6 | ||
| wrap | 1.955 | 105 | 17.5 | 26.2 | |
| wrap | 1.939 | 155 | 23.6 | 25.8 | |
| 1.885 | 694 | 90.7 | 21.0 | ||
| default, | 2.990 | 384 | 357.3 | 18.2 | |
| compact, | 2.143 | 186 | 24.8 | 29.8 | |
| 1.942 | 57 | 8.8 | 18.7 | ||
| 1.902 | 52 | 8.1 | 20.0 | ||
| 1.897 | 51 | 8.3 | 22.1 | ||
| wrap | 1.846 | 129 | 20.3 | 28.2 | |
| wrap | 1.835 | 222 | 32.1 | 27.9 | |
| 1.810 | 2099 | 266.5 | 27.8 | ||
| 1.819 | 97 | 13.5 | 23.9 | ||
| 1.819 | 90 | 13.0 | 25.5 | ||
Table 4: Query time in nanoseconds for the keys of the first level (“first”) and for all keys, measured in a separate run (medians over nine rounds of queries), so the times for all keys differ slightly from those of Tables 1 and 3; the second column is the percentage of keys bumped from the first level. We omit keys: at that size the four structures fit together in the L3 cache, which is not the case in the run of Table 2, and for PHast and PHastR the difference between the two times is below the noise of the measurement.
| Structure | bumped | keys | keys | ||
|---|---|---|---|---|---|
| first | all | first | all | ||
| wrap , | 4.2 | 3.7 | 5.7 | 17.5 | 24.5 |
| 1.0 | 4.0 | 4.5 | 18.4 | 20.3 | |
| 0.5 | 3.9 | 4.0 | 17.3 | 18.2 | |
| 1.2 | 3.8 | 4.2 | 17.1 | 19.2 | |
Number of layouts. Table 5 isolates the effect of layouts, comparing structures that differ only in their number. With 8-bit seeds and the suggested expected bucket size, going from one to four layouts reduces the bumped keys from 1.8% to 0.5% and saves 0.12 bits per key; queries become 13% faster with the same code, and another 15% faster with the code that PHastR uses with four layouts, in which the shifts are constants, so that the compiler can fuse the scaling of the seed with the addition. The advantage persists when each number of layouts uses the expected bucket size that minimizes its space: four layouts still save 0.055 bits per key with respect to one, and they are faster both to build and to query. Four layouts are also the fastest to build: only with four layouts do the bits of the ring of a key fill a single word (Section 3), and, as for queries, the construction uses code specialized for this configuration. With 10-bit seeds the reduction is smaller (from 1.4% to 0.7% of bumped keys, saving 0.06 bits per key, and 0.03 when each number of layouts uses its best expected bucket size), and the construction with four layouts is 7–8% slower than with two.
Self-collisions explain most of the reduction: with and a single layout, the buckets containing a self-collision hold 1.28% of the keys, in agreement with the first-order estimate for Poisson bucket sizes, and they contain 71% of the bumped keys; with two layouts, the buckets with a self-collision in both layouts hold just 0.03% of the keys, and with four layouts there are none, so the further reduction from two to four layouts is due to the
Table 5: PHastR with 1, 2 and 4 layouts on keys (single-threaded construction), with the suggested expected bucket size and with the one that minimizes space for each number of layouts. Queries are timed with the code used for all numbers of layouts (generic) and, for four layouts, also with the code that PHastR uses by default (specialized).
| Configuration | bits/key | bumped [%] | build [ns/key] | query [ns] | |
|---|---|---|---|---|---|
| generic | specialized | ||||
| 2.060 | 1.79 | 71 | 25.2 | – | |
| 1.952 | 0.62 | 70 | 22.2 | – | |
| 1.942 | 0.51 | 57 | 22.0 | 18.6 | |
| 1.952 | 4.12 | 60 | 29.4 | – | |
| 1.906 | 2.38 | 62 | 25.8 | – | |
| 1.897 | 2.27 | 51 | 25.5 | 22.1 | |
| 1.876 | 1.35 | 90 | 27.7 | – | |
| 1.824 | 0.78 | 89 | 26.2 | – | |
| 1.819 | 0.73 | 96 | 26.0 | 23.8 | |
| 1.849 | 2.73 | 82 | 30.3 | – | |
| 1.821 | 1.56 | 84 | 27.9 | – | |
| 1.819 | 1.52 | 90 | 27.7 | 25.5 | |
Table 6: Construction on keys (): time in nanoseconds per key by number of threads (up to 32 threads, each thread runs on a distinct core; the column labeled 96 uses the 96 hardware threads of the 48 cores), speedup with 32 threads, and peak memory usage (resident set size) with eight threads in bytes per key, excluding the keys (not measured for PtrHash). The times were measured in a separate run, so those with one thread differ slightly from those of Table 3.
| Structure | threads | speedup | bytes/key | ||||||
|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 4 | 8 | 16 | 32 | 96 | |||
| 67.8 | 36.6 | 20.7 | 12.6 | 9.0 | 7.5 | 7.2 | 9.0 | 9.8 | |
| 107.4 | 57.2 | 30.6 | 17.7 | 11.2 | 8.6 | 7.7 | 12.5 | 9.9 | |
| 696.9 | 351.2 | 177.4 | 90.9 | 47.8 | 27.7 | 16.9 | 25.2 | 10.1 | |
| PtrHash, default | 402.8 | 375.0 | 374.6 | 359.5 | 359.5 | 358.7 | 363.0 | 1.1 | – |
| PtrHash, compact | 191.6 | 96.2 | 48.0 | 24.9 | 13.6 | 8.5 | 6.4 | 22.5 | – |
| 57.8 | 30.0 | 15.5 | 8.6 | 4.9 | 3.0 | 2.5 | 19.3 | 10.7 | |
larger number of independent placements.
Construction. The construction time per key of PHastR grows slowly with the number of keys (50, 54 and 57 ns with one thread on , and keys, respectively), as parts are distributed into smaller parts that fit the cache whatever the number of keys (Section 3); the growth is mostly due to the walk finding the keys of bumped buckets, which randomly accesses the bit vector of bumped buckets.
Table 6 shows how construction scales with the number of threads: with 32 threads PHastR is built 19.3 times faster than with one, whereas PHast is built 9.0 times faster, and PHast with wrapping 12.5 times faster; the construction of PHast stops getting faster at about 7 ns per key. With all the hardware threads of the machine, the structure on keys is built in 2.5 ns per key, 2.9 times faster than PHast and 3.1 times faster than PHast with wrapping; PHast, whose construction time is dominated by the search of seeds, has the largest speedup, but it is still more than six times slower. The compact configuration of PtrHash scales well, too (22.5 times faster with 32 threads), but with all threads it is still 2.6 times slower than PHastR; the default one, which is built as a single part, does not scale. With 32 threads, the threads building PHastR are evenly loaded, and together they execute about the same number of instructions as a single thread: the loss with respect to a linear speedup comes from the lower clock frequency when many cores are active, from memory contention, and from the time spent by the kernel serving page faults. The peak memory usage is close to that of the reference implementation of PHast , which sorts hashes in place and hashes all keys again to find those of bumped buckets.
6 Offline Construction
The construction of Section 3 keeps in memory the hashes of all keys and, as bumped keys are hashed again, the keys themselves: about 11 bytes per key besides the keys. To build structures on hundreds of billions of keys, PHastR has also an offline construction, which reads the keys just once, keeps their hashes on disk, needs in memory 256 MiB of buffers while it reads the keys and then less than half a byte per key, and builds exactly the same structure. The external-memory construction of PTHash [30] also builds the same structure as its construction in memory, but since PTHash processes buckets in order of decreasing size, it must sort the hashes by bucket on disk and group the buckets by size. Beling and Sanders [4, 5] outline, but do not implement, an external-memory construction of PHast, which also sorts the hashes by bucket on disk, and reads the keys twice, the second time to find the keys of bumped buckets. In PHastR, as in the window of PHast, buckets enter the sweep in order of index, so it is sufficient to distribute the hashes into partitions, rather than sorting them. Distributing the hashes on disk by their highest bits has been a standard technique of scalable constructions of static functions and MPHFs since the work of Botelho et al. [8, 9], but these constructions build a separate structure for each partition, whereas in PHastR the linear map from hashes to buckets and the sweep in order of index make it possible to build in this way a single structure, identical to the one built in memory.
Records. The hash of a key at every level depends only on its hash h and on its second hash (Section 3). Thus, while reading the keys we compute both hashes of every key, and write a 16-byte record to temporary files: the keys are no longer necessary, and they can be streamed, for example, from a file. The records of a level are distributed into a power-of-two number of partitions by the upper bits of the hash of the key at the level. Each partition is a sequence of blocks, which are appended as their buffers fill to one of at most 16 files, each containing the blocks of a range of consecutive partitions, and a table locates the blocks of each partition.
Parts. Since hi(hB) is a nondecreasing function of h, the keys of a partition belong to consecutive buckets, and only the first and the last of these buckets can contain also keys of other partitions. Offline, the parts (Section 3), which sweeps load in increasing order, are made of consecutive partitions containing together at least 512 buckets, and a bucket whose keys lie in two parts belongs to the second one: when a sweep loads a part, it sets aside the keys found in the part that belong to the first bucket of the following part, and adds them to that part when it loads it. Thus, each partition is read once by each sweep, except at the beginning of a sweep, where the previous part might need to be read too.
Same structure. Given the slots already used, the seed chosen for a bucket depends only on the set of the hashes of its keys, and not on their order: free rotations are computed by a bitwise OR, the cost of a rotation is a sum of integers read from a table, and ties are broken by a fixed rule (Section 3). Since the sweeps see the same buckets in the same order, the structure built offline is identical to that built in memory, provided that the number of threads is the same (it determines the chunks of a parallel construction). The only difference is in the detection of duplicate keys (Section 3): as the keys are no longer available for a third hash, offline we consider duplicates two keys with the same record. The two criteria differ only in the presence of two distinct keys with the same 128 bits of hashes, in which case both constructions fail.
Following levels and memory. After the sweep of a level, its files are read again, and the records of the keys of bumped buckets are written to the files of the following level, or kept in memory if they are at most 4096: the files of the first level are written once and read twice, and the following ones are much smaller. In memory, besides the buffers of the partitions it reads, the sweep of the first level needs its seeds, as bytes when they have at most eight bits, and its set of used slots, which the sweeps of a parallel construction update directly, as each sets only the bits of its slots: with and , about bytes per key. Then, the seeds of the first level become those of the structure, its free slots are kept in an Elias–Fano sequence, and the remapping is built at the end from the sets of used slots of the following levels, which are small: from this point on, memory is essentially that of the structure being built.
Experiments. On keys the offline construction allocates at most 0.38 bytes per key with one thread and 0.41 with eight, against 9.8 and 11.4 bytes per key, excluding the keys, of the construction in memory (as measured by a counting allocator, which counts also memory that is allocated but never used: the resident set size of the construction in memory with eight threads is 10.7 bytes per key, Table 6). It takes 63.0 ns per key with one thread and 18.9 with eight, against 57.1 and 8.6 of the construction in memory in the same run: with one thread the difference is small, but with eight the time is dominated by the first phase, in which a single thread reads the keys and writes the records. On keys, the offline construction would need about 40 GB of memory and 1.6 TB of disk, whereas the construction in memory would need about 1 TB of memory besides the keys.
7 The Limits of the Approach
The first level of PHastR still bumps between 0.5% and 1.2% of the keys with 8-bit seeds and or , and, once the seed width and the expected bucket size are fixed, bumping is where the excess space goes: it is natural to ask how much a more flexible placement scheme, or a more powerful search, such as the backtracking and the local search suggested by Beling and Sanders [4, 5], could reduce it. In this section we argue that on large key sets bumping cannot be avoided, for a structural reason that applies to every placement scheme of the PHast family, and we quantify it: we derive a lower bound of about 0.1 n/W on the number of bumped keys, and we estimate that the best placement bumps about n/2W keys, that is, a fraction 1/2W of the keys, where W is the number of slots in which a key can be placed. For PHastR this is about one tenth of the keys that it bumps.
In all structures of the PHast family a key whose slice starts at can be placed only in its reach , where for PHast, for PHast with wrapping, and for PHastR, and for PHast without wrapping. The seed of a bucket chooses the slots of its keys within their reaches, but the reaches themselves depend only on the hashes of the keys. This simple constraint is sufficient to force bumping.
Proposition 1. Consider keys and slots, and assume that, for some , each key can be placed only in the slots . Let
and let be the range of . Then, every injective placement of a subset of the keys bumps (i.e., leaves out) at least keys.
Proof. For the number of keys with is . Only these keys can be placed in the slots in (which, as , lie in
Table 7: Percentage of keys that every placement must bump when each key can be placed only in the slots of its slice, for the slice starts of the first level of PHastR with on our key sets: the bound of Proposition 1, the minimum (computed by the greedy placement of Proposition 2), and the estimate , compared with the keys bumped by PHastR with .
| Keys | minimum | n/2W | PHastR | |
|---|---|---|---|---|
| 0.023 | 0.046 | 0.049 | 0.51 | |
| 0.013 | 0.053 | 0.049 | 0.52 | |
| 0.003 | 0.050 | 0.049 | 0.51 |
, so at least of these slots are free. Symmetrically, these keys can be placed only in the at most slots in , so at least of them are bumped. Since there are as many keys as slots, the number of bumped keys is equal to the number of free slots, and it is thus at least for all . Choosing as and the points at which attains its minimum and its maximum, in the appropriate order, completes the proof.
The proposition is a quantitative version of the (easy) necessity of Hall's condition [18] for the bipartite graph connecting each key to the slots of its reach. In the PHast family slice starts are computed from a hash by a multiplication in fixed-point arithmetic, so we can model them as independent and uniformly distributed. If the are independent and uniform in , then , where is Kuiper's statistic [21] of the values , that is, the sum of the maximum positive and negative deviations of their empirical distribution from the uniform distribution (the compression of slice starts into changes by at most , which does not affect the asymptotics). By Donsker's theorem [7] and the continuity of the range, converges in distribution to the range of a standard Brownian bridge (which, by Vervaat's transformation [31], has the same distribution as the maximum of a standard Brownian excursion [20]). By symmetry, the mean of the range is twice the mean of the maximum of the bridge, which exceeds with probability [7], so it is . Since is at most twice the maximum absolute deviation of the empirical distribution from the uniform distribution, the Dvoretzky-Kiefer-Wolfowitz inequality [27] shows that the tails of are sub-Gaussian, uniformly in ; thus, the convergence extends to expectations, and we conclude that
Proposition 1 uses a single interval of slots, the one between the points at which attains its minimum and its maximum, and thus it accounts only for the largest imbalance between slots and keys: it cannot exceed the range of , which grows only as , and it is a good estimate only as long as is not much larger than , that is, up to a few million keys when . However, the argument of its proof applies to every interval of slots , and to every placement: if increases by on , at least slots in are free, and if decreases by , at least keys whose reach starts in are bumped. When oscillates, several intervals have a large imbalance, and each forces its own free slots or bumped keys (Figure 5). If the intervals of slots , , ... are pairwise disjoint, a free slot lies in at most one of them, and the reach of a bumped key starts in at most one of them, so the free slots and the bumped keys counted for different intervals are distinct: the bumped keys are at least the sum of the bounds given by the intervals on which decreases, and the free slots, which are as many, at least the sum of the bounds given by the intervals on which increases. Thus, at least

Figure 5: Two disjoint intervals of slots that force bumping separately, with 32 keys, 32 slots, and reaches of W = 4 slots (the slice starts are random, but selected so as to show two large dips of X). Top: the slots; middle: the reaches of the keys, each drawn as a bar from its first to its last slot (in several lines, for readability), darker for the keys whose reach starts in one of the intervals [7..14) and [22..28) (shaded); bottom: X, with some values of t below. On the two intervals X decreases by 7 and 6: the reaches of 14 and 12 keys, respectively, start in them, and these keys can be placed only in the 10 and 9 slots indicated by the braces, so at least 4 and 3 of them, respectively, are bumped. Thus, every placement bumps at least 7 keys, which is the minimum (Proposition 2), whereas Proposition 1 guarantees only bumped keys, as the range of X is D = 8.
keys are bumped, where . The increment of on an interval of slots is asymptotically normal with mean zero and variance , so applying the bound to the consecutive intervals of slots shows that, for large , the expected number of bumped keys is at least about , where is a standard normal variable. Letting , this is , where and are the density and the distribution function of ; its maximum, attained for , that is, for intervals of about slots, is about
a constant fraction of the keys, however large the key set.
The minimum number of bumped keys can actually be computed exactly:
Proposition 2. Under the assumptions of Proposition 1, the minimum number of keys bumped by an injective placement is the number of keys bumped by the following greedy placement: for each slot, in increasing order, place in the slot the unplaced key with the smallest among those whose reach contains the slot, if any (breaking ties arbitrarily).
Proof. Let be the greedy placement and any placement. We show by induction on that there is a placement that places at least as many keys as and agrees with on the slots in , that is, places the same keys in them. For we take ; for , places the same keys as , which thus places at least as many keys as .
Let agree with on . If leaves slot free, every key whose reach contains is placed by , and thus by , before , so leaves slot free, too. Otherwise, let be the key placed by in slot , which is not placed by before . If places in slot , there is nothing to do. If leaves slot free, we move to slot (or add it, if bumps it). Otherwise, places in slot a key , which is not placed by before , so by the greedy choice. If bumps , we replace with ; if places in a slot , we exchange and , as can be placed in slot . In all cases the number of placed keys does not decrease, the slots in are unchanged, and the new placement agrees with on .
The greedy placement is a special case of Glover's algorithm for maximum matchings in convex bipartite graphs [16], which assigns each slot to the unassigned key whose interval ends first (as all reaches have the same length, the reach that ends first is the one that starts first), so Proposition 2 is a special case of Glover's theorem; we have included its short proof for completeness. Concretely, the greedy placement is a queue that at each slot receives the keys whose slice starts there, places the oldest waiting key, and bumps the keys that have waited W slots. On average one key arrives at each slot, so the length of the queue behaves like a random walk with no drift and unit variance per step, reflected at zero and at W. In the stationary regime the variance added by the arrivals must be balanced by the losses at W, each of which reduces the second moment of the length by about 2W: thus, keys are lost at a rate of about 1/2W per slot, and on large key sets the minimum number of bumped keys is about
that is, 0.049% of the keys when . Table 7 shows that this estimate is accurate on the slice starts of our key sets: on keys the minimum computed by the greedy placement is 0.050% of the keys, whereas Proposition 1 guarantees 0.003%.
In terms of space, this floor is negligible: by (1), bumping a fraction of the keys costs about bits per key when . Its importance lies in the fact that it applies to every placement: beyond a few million keys, no amount of search can make a first level with free of bumping. Consistently, the variant of PHast without bumping of the reference implementation (NBFunction) can be built in practice only with an output range larger than the number of keys, that is, when the function is not minimal: with slots the queue above has a negative drift, and its losses decrease exponentially with . On the other hand, PHastR bumps about ten times as many keys as the reaches force: most of its bumping is due to the constraints on the seeds, which offer at most placements of the keys of a bucket, rather than to the reaches. By (1), a search reaching the floor would reduce the space of PHastR with and from 1.94 to about 1.89 bits per key: this is the room that is left for better searches.
In particular, the floor rules out the possibility of obtaining a bump-free version of PHastR, whose space would be just bits per key, by a backtracking search in the style of CONSENSUS [25], which combines the search and the encoding of seeds to get arbitrarily close to the lower bound for MPHFs. For such a search to succeed, keys should be first split into subsets of exactly known size , small enough for the reaches not to force bumping, that is, with significantly smaller than , as happens (albeit for different reasons) in Bucketed CONSENSUS-RecSplit [25], whose first step is a minimal -perfect hash function.
Even within such subsets, however, a second obstacle appears: a slot becomes unreachable only after the about buckets whose slices can contain it have been placed, so a depth-first search whose only failure test is that a free slot has become unreachable must exhaust the alternatives of about buckets before it can change the choice that caused the failure. In a prototype using chained seeds as in CONSENSUS, the search never got past the first 160 buckets, even with seeds more than two bits longer than the information-theoretic minimum for a bucket , and and a budget of 2000 seeds tried per bucket, counting those tried again after backtracking.
8 Conclusions
In PHastR the lowest bits of a seed choose one of a few layouts, which are independent of one another, like the seeds of the pseudorandom scheme of PHast, and whose offsets come for free with the computation of the bucket; the remaining bits choose a rotation, which moves all the keys of the bucket by the same amount, like the seeds of the additive scheme of PHast .
Rotations keep the search bit-parallel, as the free rotations of a layout are found by cyclic shifts of the bits of the rings of the keys, which are consecutive bits once the set of used slots is stored by residue classes. Layouts, in turn, neutralize the self-collisions of the additive scheme, which, even with wrapping, cause a large part of the bumping of PHast , as a bucket is affected only if it has a self-collision in every layout; and, once the seed width and the expected bucket size are fixed, bumping is where both the excess space and the slow queries come from: queries for the keys of the first level take about the same time in PHastR and in PHast with wrapping, and almost all the difference is due to bumped keys (Table 4).
As a result, with essentially the same space as the best variant of PHast with wrapping, PHastR is built in 37% of the time, and its queries are 28% faster on keys (Tables 1–3); they are about as fast as those of PtrHash, which uses more than one bit per key more; with a larger expected bucket size, it comes within 0.02 bits per key of the space of PHast, which takes more than ten times as long to build, and still has faster queries; with many threads it is built almost three times faster than PHast (Table 6); and every configuration of PHast in Figure 4 is dominated by one of PHastR. Finally, an offline construction builds the same structure keeping the hashes of the keys on disk, with less than half a byte per key of memory on large key sets.
There are, however, intrinsic limits to how few keys can be bumped: when each key can be placed only within a range of W slots, every placement of random keys must bump, on large key sets, a constant fraction of the keys (by our lower bound, at least about 0.1/W; by our estimate, about 1/2W for the best placement), although this floor is about ten times lower than the bumping of PHastR.
There are several open problems and further research directions. On the practical side, the small final levels could be replaced by a more compact structure. More interestingly, PHastR bumps about ten times as many keys as the reaches force: it is open whether a search can approach this floor efficiently (which would save about 0.05 bits per key), and whether bump-free placements, which would use just bits per key, can be found efficiently within subsets of exactly known size, in spite of the long-range constraints that made simple backtracking fail in our prototype.
References
[1] Djamal Belazzougui, Fabiano C. Botelho, and Martin Dietzfelbinger. Hash, displace, and compress. In Algorithms – ESA 2009, 17th Annual European Symposium, volume 5757 of Lecture Notes in Computer Science, pages 682–693. Springer, 2009.
[2] Piotr Beling. Fingerprinting-based minimal perfect hashing revisited. ACM Journal of Experimental Algorithms, 28:1.4:1–1.4:16, 2023.
[3] Piotr Beling. BSuccinct: Rust libraries and programs focused on succinct data structures. SoftwareX, 26:101681, 2024.
[4] Piotr Beling and Peter Sanders. PHast — perfect hashing made fast. CoRR, abs/2504.17918, 2025.
[5] Piotr Beling and Peter Sanders. PHast — perfect hashing made fast. In Proceedings of the Symposium on Algorithm Engineering and Experiments (ALENEX 2026), pages 1–14. SIAM, 2026.
[6] Dominik Bez, Florian Kurpicz, Hans-Peter Lehmann, and Peter Sanders. High performance construction of RecSplit based minimal perfect hash functions. In 31st Annual European Symposium on Algorithms (ESA 2023), volume 274 of Leibniz International Proceedings in Informatics (LIPIcs), pages 19:1–19:16, 2023.
[7] Patrick Billingsley. Convergence of Probability Measures. Wiley, second edition, 1999.
[8] Fabiano C. Botelho, Rasmus Pagh, and Nivio Ziviani. Practical perfect hashing in nearly optimal space. Information Systems, 38(1):108–131, 2013.
[9] Fabiano C. Botelho and Nivio Ziviani. External perfect hashing for very large key sets. In 16th ACM Conference on Information and Knowledge Management (CIKM 2007), pages 653–662. ACM, 2007.
[10] Peter Elias. Efficient storage and retrieval by content and address of static files. Journal of the ACM, 21(2):246–260, 1974.
[11] Emmanuel Esposito, Thomas Mueller Graf, and Sebastiano Vigna. RecSplit: Minimal perfect hashing via recursive splitting. In Proceedings of the Symposium on Algorithm Engineering and Experiments (ALENEX 2020), pages 175–185. SIAM, 2020.
[12] Robert M. Fano. On the number of bits required to implement an associative memory. Memorandum 61, Computer Structures Group, Project MAC, MIT, Cambridge, Mass., 1971.
[13] Edward A. Fox, Qi Fan Chen, and Lenwood S. Heath. A faster algorithm for constructing minimal perfect hash functions. In Proceedings of the 15th Annual International ACM SIGIR Conference on Research and Development in Information Retrieval, pages 266–273. ACM, 1992.
[14] Michael L. Fredman and János Komlós. On the size of separating systems and families of perfect hash functions. SIAM Journal on Algebraic and Discrete Methods, 5(1):61–68, 1984.
[15] Marco Genuzio, Giuseppe Ottaviano, and Sebastiano Vigna. Fast scalable construction of ([compressed] static | minimal perfect hash) functions. Information and Computation, 273:104517, 2020.
[16] Fred Glover. Maximum matching in a convex bipartite graph. Naval Research Logistics Quarterly, 14(3):313–316, 1967.
[17] Ragnar Groot Koerkamp. PtrHash: Minimal perfect hashing at RAM throughput. In 23rd International Symposium on Experimental Algorithms (SEA 2025), volume 338 of Leibniz International Proceedings in Informatics (LIPIcs), pages 21:1–21:21. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2025.
[18] P. Hall. On representatives of subsets. Journal of the London Mathematical Society, 10(1):26–30, 1935.
[19] Stefan Hermann, Hans-Peter Lehmann, Giulio Ermanno Pibiri, Peter Sanders, and Stefan Walzer. PHOBIC: Perfect hashing with optimized bucket sizes and interleaved coding. In 32nd Annual European Symposium on Algorithms (ESA 2024), volume 308 of Leibniz International Proceedings in Informatics (LIPIcs), pages 69:1–69:17. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2024.
[20] D. P. Kennedy. The distribution of the maximum Brownian excursion. Journal of Applied Probability, 13(2):371–376, 1976.
[21] N. H. Kuiper. Tests concerning random points on a circle. Proceedings of the Koninklijke Nederlandse Akademie van Wetenschappen, Series A, 63:38–47, 1960.
[22] Hans-Peter Lehmann, Thomas Mueller, Rasmus Pagh, Giulio Ermanno Pibiri, Peter Sanders, Sebastiano Vigna, and Stefan Walzer. Modern minimal perfect hashing: A survey. ACM Computing Surveys, 58(10):1–36, 2026.
[23] Hans-Peter Lehmann, Peter Sanders, and Stefan Walzer. SicHash – small irregular cuckoo tables for perfect hashing. In Proceedings of the Symposium on Algorithm Engineering and Experiments (ALENEX 2023), pages 176–189. SIAM, 2023.
[24] Hans-Peter Lehmann, Peter Sanders, and Stefan Walzer. ShockHash: Towards optimal-space minimal perfect hashing beyond brute-force. In Proceedings of the Symposium on Algorithm Engineering and Experiments (ALENEX 2024), pages 194–206. SIAM, 2024.
[25] Hans-Peter Lehmann, Peter Sanders, Stefan Walzer, and Jonatan Ziegler. Combined search and encoding for seeds, with an application to minimal perfect hashing. In 33rd Annual European Symposium on Algorithms (ESA 2025), volume 351 of Leibniz International Proceedings in Informatics (LIPIcs), pages 109:1–109:18. Schloss Dagstuhl–Leibniz-Zentrum für Informatik, 2025.
[26] Antoine Limasset, Guillaume Rizk, Rayan Chikhi, and Pierre Peterlongo. Fast and scalable minimal perfect hashing for massive key sets. In 16th International Symposium on Experimental Algorithms (SEA 2017), volume 75 of Leibniz International Proceedings in Informatics (LIPIcs), pages 25:1–25:16, 2017.
[27] Pascal Massart. The tight constant in the Dvoretzky–Kiefer–Wolfowitz inequality. The Annals of Probability, 18(3):1269–1283, 1990.
[28] Rasmus Pagh. Hash and displace: Efficient evaluation of minimal perfect hash functions. In Algorithms and Data Structures, 6th International Workshop (WADS '99), volume 1663 of Lecture Notes in Computer Science, pages 49–54. Springer, 1999.
[29] Giulio Ermanno Pibiri and Roberto Trani. PTHash: Revisiting FCH minimal perfect hashing. In Proceedings of the 44th International ACM SIGIR Conference on Research and Development in Information Retrieval, pages 1339–1348. ACM, 2021.
[30] Giulio Ermanno Pibiri and Roberto Trani. Parallel and external-memory construction of minimal perfect hash functions with PTHash. IEEE Transactions on Knowledge and Data Engineering, 36(3):1249–1259, 2024.
[31] Wim Vervaat. A relation between Brownian bridge and Brownian excursion. The Annals of Probability, 7(1):143–149, 1979.
[32] Sebastiano Vigna. Broadword implementation of rank/select queries. In Catherine C. McGeoch, editor, Experimental Algorithms. 7th International Workshop, WEA 2008, volume 5038 of Lecture Notes in Computer Science, pages 154–168. Springer, 2008.