pub struct HashedAs<T>(/* private fields */);Expand description
HashedAs<U> can encode any feature that’s hashable. Here, U can be u8, u16, u32 or u64. Hash collisions are usually not a big problem for most uses (especially with HashedAs<u64>)
HashedAs can really speed things up where you need to do a lot of equality comparisons and your feature is longer that U. It can also provide more balanced nodes in a BTree. Currently uses FxHash.
§Example: Succinctly implementing MinHash
use creature_feature::ftzrs::bigram;
use creature_feature::traits::*;
use creature_feature::HashedAs;
use std::cmp::Reverse;
use std::collections::BinaryHeap;
// jaccard similarity is very fast on two sorted vecs, left as an exercise
fn min_hash(s: &str, n: usize) -> Vec<HashedAs<u64>> {
let heap: BinaryHeap<Reverse<HashedAs<u64>>> = bigram().featurize(s);
heap
.into_iter_sorted()
.map(|r| r.0)
.take(10)
.collect()
}Trait Implementations§
Source§impl<A: Hash> FromIterator<A> for HashedAs<u16>
impl<A: Hash> FromIterator<A> for HashedAs<u16>
Source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
Creates a value from an iterator. Read more
Source§impl<A: Hash> FromIterator<A> for HashedAs<u32>
impl<A: Hash> FromIterator<A> for HashedAs<u32>
Source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
Creates a value from an iterator. Read more
Source§impl<A: Hash> FromIterator<A> for HashedAs<u64>
impl<A: Hash> FromIterator<A> for HashedAs<u64>
Source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
Creates a value from an iterator. Read more
Source§impl<A: Hash> FromIterator<A> for HashedAs<u8>
impl<A: Hash> FromIterator<A> for HashedAs<u8>
Source§fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
fn from_iter<T>(iter: T) -> Selfwhere
T: IntoIterator<Item = A>,
Creates a value from an iterator. Read more
Source§impl<T: Ord> Ord for HashedAs<T>
impl<T: Ord> Ord for HashedAs<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd> PartialOrd for HashedAs<T>
impl<T: PartialOrd> PartialOrd for HashedAs<T>
impl<T: Copy> Copy for HashedAs<T>
impl<T: Eq> Eq for HashedAs<T>
impl IsEnabled for HashedAs<u16>
impl IsEnabled for HashedAs<u32>
impl IsEnabled for HashedAs<u64>
impl IsEnabled for HashedAs<u8>
impl<T> StructuralPartialEq for HashedAs<T>
Auto Trait Implementations§
impl<T> Freeze for HashedAs<T>where
T: Freeze,
impl<T> RefUnwindSafe for HashedAs<T>where
T: RefUnwindSafe,
impl<T> Send for HashedAs<T>where
T: Send,
impl<T> Sync for HashedAs<T>where
T: Sync,
impl<T> Unpin for HashedAs<T>where
T: Unpin,
impl<T> UnwindSafe for HashedAs<T>where
T: UnwindSafe,
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