6 releases

Uses old Rust 2015

0.3.1 Aug 9, 2022
0.3.0 Apr 29, 2022
0.2.1 Apr 19, 2021
0.1.1 Nov 15, 2019
0.1.0 Apr 23, 2018

#11 in No standard library

Download history 293554/week @ 2024-07-22 291270/week @ 2024-07-29 328847/week @ 2024-08-05 320113/week @ 2024-08-12 356653/week @ 2024-08-19 335892/week @ 2024-08-26 323242/week @ 2024-09-02 337436/week @ 2024-09-09 301651/week @ 2024-09-16 340000/week @ 2024-09-23 321665/week @ 2024-09-30 319446/week @ 2024-10-07 317617/week @ 2024-10-14 335612/week @ 2024-10-21 336153/week @ 2024-10-28 339866/week @ 2024-11-04

1,345,146 downloads per month
Used in 2,181 crates (38 directly)

MIT/Apache

13KB
248 lines

hash32

32-bit hashing machinery

Documentation

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.


lib.rs:

32-bit hashing algorithms

Why?

Because 32-bit architectures are a thing (e.g. ARM Cortex-M) and you don't want your hashing function to pull in a bunch of slow 64-bit compiler intrinsics (software implementations of 64-bit operations).

Relationship to core::hash

This crate extends core::hash with a 32-bit version of Hasher, which extends core::hash::Hasher. It requires that the hasher only performs 32-bit operations when computing the hash, and adds finish32 to get the hasher's result as a u32. The standard finish method should just zero-extend this result.

Since it extends core::hash::Hasher, Hasher can be used with any type which implements the standard Hash trait.

This crate also adds a version of BuildHasherDefault with a const constructor, to work around the core version's lack of one.

Hashers

This crate provides implementations of the following 32-bit hashing algorithms:

Generic code

In generic code, the trait bound H: core::hash::Hasher accepts both 64-bit hashers like std::collections::hash_map::DefaultHasher; and 32-bit hashers like the ones defined in this crate (hash32::FnvHasher and hash32::Murmur3Hasher)

The trait bound H: hash32::Hasher is more restrictive as it only accepts 32-bit hashers.

The BuildHasherDefault<H> type implements the core::hash::BuildHasher trait so it can construct both 32-bit and 64-bit hashers. To constrain the type to only produce 32-bit hasher you can add the trait bound H::Hasher: hash32::Hasher

MSRV

This crate is guaranteed to compile on latest stable Rust. It might compile on older versions but that may change in any new patch release.

Dependencies

~115KB