Given a set $S$ of $n$ keys, a minimal perfect hash function (MPHF) is a collision-free bijective map $\mathsf{H_{mphf}}$ from $S$ to $\{0, \dots, n-1\}$. This work presents a (minimal) perfect hash function that first prioritizes query throughput, while also allowing efficient construction for $10^9$ or more elements using 2.4 bits of memory per key. Both PTHash and PHOBIC first map all $n$ keys to $n/\lambda < n$ buckets. Then, each bucket stores a pilot that controls the final hash value of the keys mapping to it. PtrHash builds on this by using 1) fixed-width (uncompressed) 8-bit pilots, 2) a construction algorithm similar to cuckoo-hashing to find suitable pilot values. Further, it 3) uses the same number of buckets and slots for each part, with 4) a single remap table to map intermediate positions $\geq n$ to $<n$, 5) encoded using per-cacheline Elias-Fano coding. Lastly, 6) PtrHash support streaming queries, where we use prefetching to answer a stream of multiple queries more efficiently than one-by-one processing. With default parameters, PtrHash takes 2.40 bits per key. On 300 million string keys, PtrHash is as fast or faster to build than other MPHFs, and at least $1.75\times$ faster to query. When streaming multiple queries, this improves to $3.1\times$ speedup over the fastest alternative, while also being significantly faster to construct. When using $10^9$ integer keys instead, query times are as low as 12 ns/key when iterating in a for loop, or even down to 8 ns/key when using the streaming approach, within $10\%$ of the maximum memory-bound throughput.
翻译:给定一个包含 $n$ 个键的集合 $S$,最小完美哈希函数(MPHF)是一个从 $S$ 到 $\{0, \dots, n-1\}$ 的无碰撞双射映射 $\mathsf{H_{mphf}}$。本文提出了一种(最小)完美哈希函数,其首要设计目标是查询吞吐量,同时也能以每个键 2.4 比特的内存使用量,高效地构建适用于 $10^9$ 或更多元素的哈希函数。PTHash 和 PHOBIC 都首先将所有 $n$ 个键映射到 $n/\lambda < n$ 个桶中。然后,每个桶存储一个引导值,该值控制映射到该桶的键的最终哈希值。PtrHash 在此基础上进行了改进,它采用:1) 固定宽度(未压缩的)8 比特引导值;2) 一种类似于布谷鸟哈希的构建算法来寻找合适的引导值。此外,它 3) 对每个部分使用相同数量的桶和槽位;4) 使用单个重映射表将中间位置 $\geq n$ 映射到 $<n$;5) 采用每缓存行的 Elias-Fano 编码进行编码。最后,6) PtrHash 支持流式查询,我们利用预取技术来比逐个处理更高效地回答多个查询流。在默认参数下,PtrHash 每个键占用 2.40 比特。在 3 亿个字符串键上,PtrHash 的构建速度与其他 MPHF 相当或更快,查询速度至少快 $1.75\times$。当处理流式多查询时,相对于最快的替代方案,其速度提升达到 $3.1\times$,同时构建速度也显著更快。当使用 $10^9$ 个整数键时,在 for 循环中迭代的查询时间低至 12 纳秒/键,而使用流式方法时甚至可降至 8 纳秒/键,接近内存最大吞吐量的 $10\%$ 以内。