QuickPHF
QuickPHF is a Rust crate that allows you to use static compile-time generated hash maps and hash sets using PTHash perfect hash functions.
This crate only contains the runtime code required for using such structures.
To generate them, look at the quickphf_codegen crate
instead.
The minimum supported Rust version is 1.56. This crate is #![no_std] and
#![forbid(unsafe_code)].
Features
- Provides 3 perfect hash function-backed data structures:
PhfMapandPhfSet, which, for ease of use, mimic the immutable part of the interface of the standard libraryHashMapandHashSet; andRawPhfMap, which is a hash map that does not store its keys. - About twice as fast as
phfat lookup, and more than 10 times faster at construction. - Uses a Rust implementation of
Wang Yi's
wyhashalgorithm for hashing. - Uses the
quickdivcrate to speed up modulo computations. - Very low memory usage: no unused capacity and less than a byte of overhead per entry.
Example
use *;
// You can use `PhfMap` or `PhfSet` just like `HashMap` or `HashSet`.
assert_eq!;
assert_eq!;
assert!;
assert_eq!;
// With a `RawPhfMap` you would mostly use the `get` method. Note
// that it directly returns a &T instead of an Option<&T>.
assert_eq!;
// If you query for an invalid key, it will silently return an
// arbitrary answer.
let valid_reference = HOLIDAYS_PER_MONTH.get;
Performance
In general, quickphf is about twice as fast as phf at lookup, with RawPhfMap
being faster than PhfMap, especially for larger hash maps.

License
Licensed under any of:
- Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
- zlib License (LICENSE-ZLIB or https://opensource.org/license/zlib/)
at your choice.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be multi-licensed as above, without any additional terms or conditions.