hash_hasher 0.3.0

A hasher which is designed to work with already-hashed or hash-like data.
Documentation

hash_hasher

A std::hash::Hasher which is designed to work with already-hashed or hash-like data.

Documentation Build status Build Status

Details

The provided hasher does minimal work under the assumption that the input data is already suitable for use as a key in a HashSet or HashMap.

As well as the performance benefit, it also causes HashSets or HashMaps to become somewhat deterministic. Given two equal HashSets or HashMaps containing more than a single element, iterating them will yield the elements in differing orders. By using a HashSet<_, HashBuildHasher> or HashMap<_, _, HashBuildHasher>, then if the same data is inserted and/or removed in the same order, iterating the collection will yield a consistent order.

Example

extern crate hash_hasher;

use std::collections::HashMap;
use hash_hasher::HashBuildHasher;

let hash_builder = HashBuildHasher::default();
let mut map: HashMap<u16, &str, HashBuildHasher> = HashMap::with_hasher(hash_builder);

assert!(map.insert(0, "zero").is_none());
assert!(map.insert(1024, "1024").is_none());
assert_eq!(Some("zero"), map.insert(0, "nothing"));

Benchmarks

A benchmark suite is included and sample figures can be found at the end of the AppVeyor results and the nightly jobs of the Travis results.

For example:

insert_sha1s_into_set_using_default_hasher      ... bench:       3,382 ns/iter (+/- 276)
insert_sha1s_into_set_using_hash_hasher         ... bench:       1,657 ns/iter (+/- 166)

insert_sha256s_into_set_using_default_hasher    ... bench:       4,002 ns/iter (+/- 374)
insert_sha256s_into_set_using_hash_hasher       ... bench:       1,523 ns/iter (+/- 82)

insert_sha512s_into_set_using_default_hasher    ... bench:       5,128 ns/iter (+/- 228)
insert_sha512s_into_set_using_hash_hasher       ... bench:       1,859 ns/iter (+/- 109)

insert_sip_hashes_into_set_using_default_hasher ... bench:       2,351 ns/iter (+/- 171)
insert_sip_hashes_into_set_using_hash_hasher    ... bench:         630 ns/iter (+/- 13)

License

Licensed under either of

at your option.

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 dual licensed as above, without any additional terms or conditions.