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.
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
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 moreAuto Trait Implementations§
impl Freeze for RandomProjectionHasher
impl RefUnwindSafe for RandomProjectionHasher
impl Send for RandomProjectionHasher
impl Sync for RandomProjectionHasher
impl Unpin for RandomProjectionHasher
impl UnsafeUnpin for RandomProjectionHasher
impl UnwindSafe for RandomProjectionHasher
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