pub struct FeatureHasher { /* private fields */ }Expand description
Fixed-dimension feature hasher.
Uses two independent hash functions:
- The first determines the target bucket (
hash1 % dimension). - The second determines the sign (
hash2 & 1) whensigned = true.
The hash is deterministic given the same seed, ensuring reproducible
output across runs.
Implementations§
Source§impl FeatureHasher
impl FeatureHasher
Sourcepub fn new(dimension: usize, seed: u64) -> Result<Self, RillError>
pub fn new(dimension: usize, seed: u64) -> Result<Self, RillError>
Create a new hasher with the given dimension and seed.
Uses signed hashing by default.
Sourcepub fn with_config(config: FeatureHasherConfig) -> Result<Self, RillError>
pub fn with_config(config: FeatureHasherConfig) -> Result<Self, RillError>
Create a new hasher with a custom configuration.
Sourcepub fn hash_string(&self, name: &str) -> FeatureId
pub fn hash_string(&self, name: &str) -> FeatureId
Hash a string feature name to a FeatureId.
Sourcepub fn hash_strings(
&self,
pairs: &[(&str, f64)],
) -> Result<SparseFeatures, RillError>
pub fn hash_strings( &self, pairs: &[(&str, f64)], ) -> Result<SparseFeatures, RillError>
Create SparseFeatures from string name/value pairs.
Each string is hashed to a FeatureId, then the pairs are sorted
and duplicates are merged by summing values.
Trait Implementations§
Source§impl Clone for FeatureHasher
impl Clone for FeatureHasher
Source§fn clone(&self) -> FeatureHasher
fn clone(&self) -> FeatureHasher
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 FeatureHasher
impl RefUnwindSafe for FeatureHasher
impl Send for FeatureHasher
impl Sync for FeatureHasher
impl Unpin for FeatureHasher
impl UnsafeUnpin for FeatureHasher
impl UnwindSafe for FeatureHasher
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