Struct fhash::RandomState

source ·
pub struct RandomState { /* private fields */ }
Expand description

State used for the random hashing algorithm in HashMap and HashSet. RandomState introduces randomness into the hashing process to mitigate certain types of hash collision attacks, enhancing the security and resilience of the data structures. It is designed to make it harder for attackers to predict hash values and exploit vulnerabilities in the hash function.

Example

use hashbrown::HashMap;
use fhash::RandomState;

// Create a HashMap using RandomState as the hasher
let mut map: HashMap<i32, &str, RandomState> = HashMap::default();

// Inserting values into the HashMap
map.insert(1, "apple");
map.insert(2, "banana");

// Retrieve values from the HashMap
assert_eq!(map.get(&1), Some(&"apple"));
assert_eq!(map.get(&2), Some(&"banana"));

Trait Implementations§

source§

impl BuildHasher for RandomState

source§

fn build_hasher(&self) -> FHasher

Builds a new FHasher using the current RandomState’s state.

§

type Hasher = FHasher

Type of the hasher that will be created.
1.71.0 · source§

fn hash_one<T>(&self, x: T) -> u64
where T: Hash, Self: Sized, Self::Hasher: Hasher,

Calculates the hash of a single value. Read more
source§

impl Default for RandomState

source§

fn default() -> Self

Creates a new RandomState with state seeded from current time.

source§

impl From<u64> for RandomState

source§

fn from(state: u64) -> Self

Use custom u64 value as a seed for RandomState. Useful in no_std scenarios or environments with limited standard library access where direct construction from a u64 value is beneficial.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.