pub struct RandomProjectionHasher { /* private fields */ }Expand description
A random-projection hash family for one hash table.
Uses sign-of-random-projection (SimHash / hyperplane LSH) to map vectors to bit signatures. Each bit corresponds to the sign of the dot product with a random Gaussian vector.
Projections are stored as a (num_hashes x dim) matrix so that all dot products can be computed in a single matrix-vector multiply.
Implementations§
Source§impl RandomProjectionHasher
impl RandomProjectionHasher
Sourcepub fn new(dim: usize, num_hashes: usize, rng: &mut impl Rng) -> Self
pub fn new(dim: usize, num_hashes: usize, rng: &mut impl Rng) -> Self
Create a new hasher with num_hashes random projection vectors of dimension dim.
Sourcepub fn hash_vector(
&self,
vector: &ArrayView1<'_, f32>,
) -> (u64, Vec<(usize, f32)>)
pub fn hash_vector( &self, vector: &ArrayView1<'_, f32>, ) -> (u64, Vec<(usize, f32)>)
Compute the hash key for a vector, along with margin information for multi-probe.
Returns (hash_key, margins) where margins is a vec of (bit_index, |dot_product|)
sorted by ascending margin (most uncertain bits first).
Sourcepub fn hash_vector_fast(&self, vector: &ArrayView1<'_, f32>) -> u64
pub fn hash_vector_fast(&self, vector: &ArrayView1<'_, f32>) -> u64
Compute just the hash key (fast path, no margin data).
Sourcepub fn num_hashes(&self) -> usize
pub fn num_hashes(&self) -> usize
Number of hash functions (bits in the signature).
Trait Implementations§
Source§impl Clone for RandomProjectionHasher
impl Clone for RandomProjectionHasher
Source§fn clone(&self) -> RandomProjectionHasher
fn clone(&self) -> RandomProjectionHasher
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more