|
8 | 8 | //!
|
9 | 9 | //! # Relationship to `core::hash`
|
10 | 10 | //!
|
11 |
| -//! This crate extends [`core::hash`] with a 32-bit version of `Hasher`, which extends |
12 |
| -//! `core::hash::Hasher`. It requires that the hasher only performs 32-bit operations when computing |
13 |
| -//! the hash, and adds [`finish32`] to get the hasher's result as a `u32`. The standard `finish` |
14 |
| -//! method should just zero-extend this result. |
| 11 | +//! This crate extends [`core::hash::Hasher`] with a 32-bit version, [`hash32::Hasher`]. |
15 | 12 | //!
|
16 |
| -//! Since it extends `core::hash::Hasher`, `Hasher` can be used with any type which implements the |
17 |
| -//! standard `Hash` trait. |
| 13 | +//! The [`hash32::Hasher`] trait requires the hasher to perform only 32-bit operations when |
| 14 | +//! computing the hash. |
| 15 | +//! The trait method [`hash32::Hasher::finish32`] returns the hasher's result as a `u32`. |
| 16 | +//! The [`core::hash::Hasher::finish`] method zero-extends the [`hash32::Hasher::finish32`] |
| 17 | +//! result to a `u64`. |
18 | 18 | //!
|
| 19 | +//! Since [`hash32::Hasher`] extends [`core::hash::Hasher`], the [`hash32::Hasher`] trait can be |
| 20 | +//! used with any type which implements the [`core::hash::Hash`] trait. |
| 21 | +//! |
| 22 | +//! [`hash32::Hasher`]: crate::Hasher |
| 23 | +//! [`hash32::Hasher::finish32`]: crate::Hasher::finish32 |
19 | 24 | //! [`core::hash`]: https://doc.rust-lang.org/std/hash/index.html
|
20 | 25 | //! [`finish32`]: crate::Hasher::finish32
|
21 | 26 | //!
|
|
26 | 31 | //! - [`FnvHasher`] Fowler-Noll-Vo 1a
|
27 | 32 | //! - [`Murmur3Hasher`] `MurmurHash3`
|
28 | 33 | //!
|
| 34 | +//! ## Picking a hasher |
| 35 | +//! |
| 36 | +//! - [`FnvHasher`] is faster and consumes less code space than [`Murmur3Hasher`]. |
| 37 | +//! - [`Murmur3Hasher`] offers better collision resistance than [`FnvHasher`]. |
| 38 | +//! |
| 39 | +//! ## Security |
| 40 | +//! |
| 41 | +//! Hashers provided by this crate are not cryptographically secure, and must **not** be used |
| 42 | +//! for security purposes. |
| 43 | +//! Additionally, unlike [`std::hash::DefaultHasher`] the provided hash algorithms lack |
| 44 | +//! denial-of-service protection, and must only be used with trusted data. |
| 45 | +//! |
29 | 46 | //! # Generic code
|
30 | 47 | //!
|
31 |
| -//! In generic code, the trait bound `H: core::hash::Hasher` accepts *both* 64-bit hashers like |
32 |
| -//! `std::collections::hash_map::DefaultHasher`; and 32-bit hashers like the ones defined in this |
33 |
| -//! crate (`hash32::FnvHasher` and `hash32::Murmur3Hasher`) |
| 48 | +//! In generic code, the trait bound `H: core::hash::Hasher` accepts **both** 64-bit hashers such |
| 49 | +//! as [`std::hash::DefaultHasher`]; and 32-bit hashers such as the ones defined in this crate, |
| 50 | +//! [`FnvHasher`], and [`Murmur3Hasher`]. |
| 51 | +//! |
| 52 | +//! The trait bound `H: hash32::Hasher` is **more** restrictive as it only accepts 32-bit hashers. |
34 | 53 | //!
|
35 |
| -//! The trait bound `H: hash32::Hasher` is *more* restrictive as it only accepts 32-bit hashers. |
| 54 | +//! [`std::hash::DefaultHasher`]: https://doc.rust-lang.org/std/hash/struct.DefaultHasher.html |
36 | 55 | //!
|
37 | 56 | //! # MSRV
|
38 | 57 | //!
|
|
0 commit comments