#hasher #hash #hash-set #hash-map

hash_hasher

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

6 stable releases

2.0.3 Feb 28, 2020
2.0.2 Dec 11, 2019
2.0.0 Apr 28, 2019
1.1.0 Apr 10, 2019
0.1.0 May 19, 2016

#202 in Data structures

Download history 45318/week @ 2024-07-25 47595/week @ 2024-08-01 44809/week @ 2024-08-08 55002/week @ 2024-08-15 61258/week @ 2024-08-22 60809/week @ 2024-08-29 57347/week @ 2024-09-05 41197/week @ 2024-09-12 36479/week @ 2024-09-19 42645/week @ 2024-09-26 37898/week @ 2024-10-03 34512/week @ 2024-10-10 39546/week @ 2024-10-17 43985/week @ 2024-10-24 36385/week @ 2024-10-31 34184/week @ 2024-11-07

161,448 downloads per month
Used in 199 crates (13 directly)

Apache-2.0 OR MIT

13KB
142 lines

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 hash_hasher::HashedSet or hash_hasher::HashedMap, then if the same data is inserted and/or removed in the same order, iterating the collection will yield a consistent order.

Example

Since new() and with_capacity() aren't available for HashSets or HashMaps using custom hashers, the available constructors are default(), with_hasher() and with_capacity_and_hasher().

extern crate hash_hasher;

use hash_hasher::{HashBuildHasher, HashedMap, HashedSet};

let mut map = HashedMap::default();
assert!(map.insert(0, "zero").is_none());

let mut set = HashedSet::with_capacity_and_hasher(100, HashBuildHasher::default());
assert!(set.insert(0));

Benchmarks

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

For example:

insert_sha1s_into_set_using_default_hasher      ... bench:       1,171 ns/iter (+/- 30)
insert_sha1s_into_set_using_hash_hasher         ... bench:         533 ns/iter (+/- 9)

insert_sha256s_into_set_using_default_hasher    ... bench:       1,340 ns/iter (+/- 57)
insert_sha256s_into_set_using_hash_hasher       ... bench:         546 ns/iter (+/- 11)

insert_sha512s_into_set_using_default_hasher    ... bench:       1,804 ns/iter (+/- 2,597)
insert_sha512s_into_set_using_hash_hasher       ... bench:         704 ns/iter (+/- 22)

insert_sip_hashes_into_set_using_default_hasher ... bench:         781 ns/iter (+/- 33)
insert_sip_hashes_into_set_using_hash_hasher    ... bench:         256 ns/iter (+/- 50)

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.

No runtime deps