pub struct FastHasher { /* private fields */ }Expand description
A fast hasher for computing multiple hash values efficiently.
This struct uses a family of permutation hash functions suitable for MinHash.
The hash functions have the form: h_i(x) = (a_i * x + b_i) mod p
where p is a large prime and a_i, b_i are random odd coefficients.
Implementations§
Source§impl FastHasher
impl FastHasher
Sourcepub fn new(num_hashes: usize, seed: u64) -> Self
pub fn new(num_hashes: usize, seed: u64) -> Self
Create a new hasher with the given number of hash functions.
A count of 0 returns a no-op hasher with empty coefficients. Counts
above [crate::config::MAX_SIGNATURE_SIZE] are clamped to it: the
coefficients are two u64 vectors of this length, so an unbounded
count (for example usize::MAX from a hostile or mistaken caller)
would abort the process on allocation failure.
Sourcepub fn hash_shingle(&self, shingle: u64) -> Vec<u32>
pub fn hash_shingle(&self, shingle: u64) -> Vec<u32>
Compute MinHash signature for a single shingle value.
Returns a vector of hash values, one per hash function. For MinHash, we take the minimum across all shingles.
Sourcepub fn update_signature(&self, signature: &mut [u32], shingle: u64)
pub fn update_signature(&self, signature: &mut [u32], shingle: u64)
Update a signature in-place with a new shingle using MINimum update.
For each hash function, updates signature[i] = min(signature[i], hash_i(shingle)).
Sourcepub fn update_signature_batch(&self, signature: &mut [u32], shingles: &[u64])
pub fn update_signature_batch(&self, signature: &mut [u32], shingles: &[u64])
Batch hash multiple shingles and update signature.
This is more cache-efficient than calling update_signature repeatedly.
Sourcepub const fn num_hashes(&self) -> usize
pub const fn num_hashes(&self) -> usize
Get the number of hash functions.
Trait Implementations§
Source§impl Clone for FastHasher
impl Clone for FastHasher
Source§fn clone(&self) -> FastHasher
fn clone(&self) -> FastHasher
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more