pub struct HashFunction { /* private fields */ }Expand description
A hash function with configurable algorithm and seed
Implementations§
Source§impl HashFunction
impl HashFunction
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new hash function with the default algorithm
§Examples
use yimi_rutool::algorithms::hash_functions::{HashFunction, Hasher};
let hash_fn = HashFunction::new();
let hash_value = hash_fn.hash("hello");
assert!(hash_value > 0);Sourcepub fn with_algorithm(algorithm: HashAlgorithm) -> Self
pub fn with_algorithm(algorithm: HashAlgorithm) -> Self
Create a new hash function with a specific algorithm
§Arguments
algorithm- The hash algorithm to use
§Examples
use yimi_rutool::algorithms::hash_functions::{HashFunction, HashAlgorithm, Hasher};
let hash_fn = HashFunction::with_algorithm(HashAlgorithm::Murmur3);
let hash_value = hash_fn.hash("hello");
assert!(hash_value > 0);Sourcepub fn with_seed(algorithm: HashAlgorithm, seed: u64) -> Self
pub fn with_seed(algorithm: HashAlgorithm, seed: u64) -> Self
Create a new hash function with a specific algorithm and seed
§Arguments
algorithm- The hash algorithm to useseed- Seed value for the hash function
§Examples
use yimi_rutool::algorithms::hash_functions::{HashFunction, HashAlgorithm, Hasher};
let hash_fn = HashFunction::with_seed(HashAlgorithm::Fnv1a, 12345);
let hash_value = hash_fn.hash("hello");
assert!(hash_value > 0);Sourcepub fn generate_functions(count: usize) -> Vec<HashFunction>
pub fn generate_functions(count: usize) -> Vec<HashFunction>
Generate multiple hash functions with different seeds
This is useful for bloom filters that need multiple independent hash functions.
§Arguments
count- Number of hash functions to generate
§Examples
use yimi_rutool::algorithms::hash_functions::HashFunction;
let hash_functions = HashFunction::generate_functions(5);
assert_eq!(hash_functions.len(), 5);Sourcepub fn algorithm(&self) -> HashAlgorithm
pub fn algorithm(&self) -> HashAlgorithm
Get the algorithm used by this hash function
Trait Implementations§
Source§impl Clone for HashFunction
impl Clone for HashFunction
Source§fn clone(&self) -> HashFunction
fn clone(&self) -> HashFunction
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HashFunction
impl Debug for HashFunction
Source§impl Default for HashFunction
impl Default for HashFunction
Auto Trait Implementations§
impl Freeze for HashFunction
impl RefUnwindSafe for HashFunction
impl Send for HashFunction
impl Sync for HashFunction
impl Unpin for HashFunction
impl UnwindSafe for HashFunction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().