10 releases

new 0.5.8 Nov 24, 2020
0.5.7 Nov 23, 2020
0.5.5 Jul 13, 2020
0.5.4 Mar 26, 2020
0.2.0 Jan 6, 2018

#52 in Cryptography

Download history 472/week @ 2020-08-09 298/week @ 2020-08-16 292/week @ 2020-08-23 163/week @ 2020-08-30 219/week @ 2020-09-06 199/week @ 2020-09-13 477/week @ 2020-09-20 257/week @ 2020-09-27 418/week @ 2020-10-04 527/week @ 2020-10-11 281/week @ 2020-10-18 435/week @ 2020-10-25 279/week @ 2020-11-01 308/week @ 2020-11-08 440/week @ 2020-11-15 277/week @ 2020-11-22

1,406 downloads per month
Used in 6 crates (via debruijn)

MIT license

66KB
1.5K SLoC

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 {
    hashes.push(phf.hash(&v));
}
hashes.sort();

// 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.

Dependencies

~1.5MB
~33K SLoC