kvarn_async::prelude::compact_str::core::hash

Trait BuildHasher

1.7.0 · source
pub trait BuildHasher {
    type Hasher: Hasher;

    // Required method
    fn build_hasher(&self) -> Self::Hasher;

    // Provided method
    fn hash_one<T>(&self, x: T) -> u64
       where T: Hash,
             Self: Sized,
             Self::Hasher: Hasher { ... }
}
Expand description

A trait for creating instances of Hasher.

A BuildHasher is typically used (e.g., by HashMap) to create Hashers for each key such that they are hashed independently of one another, since Hashers contain state.

For each instance of BuildHasher, the Hashers created by build_hasher should be identical. That is, if the same stream of bytes is fed into each hasher, the same output will also be generated.

§Examples

use std::hash::{BuildHasher, Hasher, RandomState};

let s = RandomState::new();
let mut hasher_1 = s.build_hasher();
let mut hasher_2 = s.build_hasher();

hasher_1.write_u32(8128);
hasher_2.write_u32(8128);

assert_eq!(hasher_1.finish(), hasher_2.finish());

Required Associated Types§

1.7.0 · source

type Hasher: Hasher

Type of the hasher that will be created.

Required Methods§