int_hash 0.1.1

Very fast, very simple hash algorithm designed for use in integer hash maps & sets.
Documentation

int_hash crates.io Documentation

Very fast, very simple hash algorithm designed for use in integer hash maps & sets.

This crate attempts to provide the fastest option for integer key hashmaps in the Rust language. So the algorithm may change if a better method is found for this use case.

use int_hash::IntHashMap;
let mut map: IntHashMap<u32, &str> = IntHashMap::default();
map.insert(22, "abc");

Benchmark Performance

For more info see the the full benchmark report.

Hash Algorithm Integer Sample Set int_hash is
Rust default aka SipHash ℕ: Natural numbers 2.53-9.06x faster
Rust default aka SipHash Random numbers 1.18-3.90x faster
Rust default aka SipHash 32× table 1.49-3.13x faster
fnv ℕ: Natural numbers 1.31-5.84x faster
fnv Random numbers 1.00-1.84x faster
fnv 32× table 0.59-1.14x faster
rustc-hash aka fx ℕ: Natural numbers 1.14-2.48x faster
rustc-hash aka fx Random numbers 0.95-1.07x faster
rustc-hash aka fx 32× table 0.97-1.13x faster
seahash ℕ: Natural numbers 2.71-10.67x faster
seahash Random numbers 1.11-2.61x faster
seahash 32× table 1.29-2.14x faster
twox_hash aka xx ℕ: Natural numbers 2.93-9.85x faster
twox_hash aka xx Random numbers 1.20-4.17x faster
twox_hash aka xx 32× table 1.55-3.64x faster

Limitations

int_hash is valid for use only with integer sized data, ie <= 16 bytes. This is enforced with debug assertions. This should guarantee that whenever int_hash works it's among the fastest options.

The algorithm is non-cryptographic.

Why is it so fast

int_hash is dedicated at solving integer-sized hashing and only integer-sized hashing. Producing a unique u64 from an integer is not a very difficult problem, though getting a good spread of values to minimise hashmap collisions is a little harder.

The current implementation uses simple usize XOR mixing to spread values. The sheer simplicity of this approach makes the hashing operation very fast and the primitive spreading is good enough to produce best-in-class hashmap performance.