Crate ph

source ·
Expand description

ph is the Rust library (by Piotr Beling) of data structures based on perfect hashing.

The library contains an implementation of two variants of the fingerprint-based minimal perfect hash function without (FMPH, fmph::Function) and with (FMPHGO, fmph::GOFunction) group optimization. A minimal perfect hash function (MPHF) is a bijection from a key set K to the set {0, 1, …, |K|−1}.

FMPH and FMPHGO can be constructed for any set K (given in advance) of hashable items and represented using about 2.8 and 2.1 bits per key (regardless of key types), respectively. FMPH and FMPHGO are fast (O(1)) to evaluate. Their construction requires very little auxiliary memory, takes a short (O(|K|)) time (which is especially true for FMPH) and, in addition, can be parallelized.


When using ph for research purposes, please cite the following paper which provides details on FMPH and FMPHGO:


use ph::fmph;

let keys = ['a', 'b', 'z'];
let f = fmph::Function::from(&keys[..]);
// f assigns each key a unique number from the set {0, 1, 2}
for k in keys { println!("The key {} is assigned the value {}.", k, f.get(&k).unwrap()); }
let mut values = [f.get(&'a').unwrap(), f.get(&'b').unwrap(), f.get(&'z').unwrap()];
assert_eq!(values, [0, 1, 2]);



  • Fingerprint-based minimal perfect hashing.
  • Families of hash functions, seedable hashers.
  • Collecting and reporting building and querying statistics.
  • Utility functions.


  • Provides methods to get dynamic and total size of the variable.