petgraph icon indicating copy to clipboard operation
petgraph copied to clipboard

Allow alternative hash functions in GraphMap

Open daniel-levin opened this issue 11 months ago • 0 comments

Hi there @bluss and @ABorgna!

Today, GraphMap uses IndexMap's default choice of hash function. Like many Rustaceans, I have a use case that is bottlenecked by hashing, which could take advantage of a faster hash function.

This change allows users of this crate to pick alternative hashers, as they might with an IndexMap or a HashMap, but only if they want to. Existing code will still work, because each impl has been made more generic, since std::hash::RandomState already implements BuildHasher and Default.

I took dev-dependencies on ahash and fxhash, and extended a benchmark I'd previously contributed:

running 3 tests
test graphmap_serial_bench        ... bench: 208,458,239 ns/iter (+/- 6,845,112)
test graphmap_serial_bench_ahash  ... bench: 171,139,041 ns/iter (+/- 3,972,136)
test graphmap_serial_bench_fxhash ... bench: 183,217,281 ns/iter (+/- 55,096,481)

daniel-levin avatar Mar 22 '24 06:03 daniel-levin