Trait CallHasher

Source
pub trait CallHasher {
    // Required method
    fn get_hash<H: Hash + ?Sized, B: BuildHasher>(
        value: &H,
        build_hasher: &B,
    ) -> u64;
}
Expand description

Provides a way to get an optimized hasher for a given data type. Rather than using a Hasher generically which can hash any value, this provides a way to get a specialized hash for a specific type. So this may be faster for primitive types.

§Example

use std::hash::BuildHasher;
use ahash::RandomState;
use ahash::CallHasher;

let hash_builder = RandomState::new();
//...
let value: u32 = 17;
let hash = u32::get_hash(&value, &hash_builder);

Note that the type used to invoke get_hash must be the same a the type of value passed. For example get a hasher specialized on [u8] can invoke:

/// use std::hash::BuildHasher;
let bytes: [u8; 4] = [1, 2, 3, 4];
let hash = <[u8]>::get_hash(&bytes, &hash_builder);

Required Methods§

Source

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl CallHasher for i8

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for i16

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for i32

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for i64

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for i128

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for isize

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for str

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for u8

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for u16

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for u32

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for u64

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for u128

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for usize

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for String

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for Vec<u8>

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Source§

impl CallHasher for [u8]

Source§

fn get_hash<H: Hash + ?Sized, B: BuildHasher>( value: &H, build_hasher: &B, ) -> u64

Implementors§

Source§

impl<T> CallHasher for T
where T: Hash + ?Sized,