#hashing #minimal #perfect


Scalable and Efficient Minimal Perfect Hash Functions (version modified by Piotr Beling)

1 unstable release

0.5.9+1 Dec 5, 2022
0.5.9-0 Dec 11, 2022

#6 in #perfect

Download history 18/week @ 2023-06-02 15/week @ 2023-06-09 31/week @ 2023-06-16 28/week @ 2023-06-23 27/week @ 2023-06-30 30/week @ 2023-07-07 22/week @ 2023-07-14 21/week @ 2023-07-21 19/week @ 2023-07-28 20/week @ 2023-08-04 17/week @ 2023-08-11 19/week @ 2023-08-18 17/week @ 2023-08-25 16/week @ 2023-09-01 10/week @ 2023-09-08 5/week @ 2023-09-15

51 downloads per month
Used in mphf_benchmark

MIT license

1.5K SLoC


This is a slightly modified (by Piotr Beling; for benchmark purposes) version of boomphf by Patrick Marks. Please use the original version instead of this one.

Fast and Scalable Minimal Perfect Hash Functions in Rust

A Rust impl of Fast and scalable minimal perfect hashing for massive key sets.

The library generates a minimal perfect hash functions (MPHF) for a collection of hashable objects. This algorithm generates MPHFs that consume ~3-6 bits/item. The memory consumption during construction is a small multiple (< 2x) of the size of the dataset and final size of the MPHF. Note, minimal perfect hash functions only return a usable hash value for objects in the set used to create the MPHF. Hashing a new object will return an arbitrary hash value. If your use case may result in hashing new values, you will need an auxiliary scheme to detect this condition.

See Docs

Example usage:

use boomphf::*;

// sample set of obejcts
let possible_objects = vec![1, 10, 1000, 23, 457, 856, 845, 124, 912];
let n = possible_objects.len();

// generate a minimal perfect hash function of these items
let phf = Mphf::new(1.7, possible_objects.clone(), None);

// Get hash value of all objects
let mut hashes = Vec::new();
for v in possible_objects {

// Expected hash output is set of all integers from 0..n
let expected_hashes: Vec<u64> = (0 .. n as u64).collect();
assert!(hashes == expected_hashes)

Note: this crate carries it's own bit-vector implementation to support rank-select queries and multi-threaded read-write access.


~29K SLoC