pub struct Prehashed<T: ?Sized> { /* private fields */ }Expand description
A wrapper type with precomputed hash.
This is useful if you want to pass large values of T to memoized
functions. Especially recursive structures like trees benefit from
intermediate prehashed nodes.
Note that for a value v of type T, hash(v) is not necessarily equal to
hash(Prehashed::new(v)). Writing the precomputed hash into a hasher’s
state produces different output than writing the value’s parts directly.
However, that seldomly matters as you are typically either dealing with
values of type T or with values of type Prehashed<T>, not a mix of both.
Equality
Because comemo uses high-quality 128 bit hashes in all places, the risk of a
hash collision is reduced to an absolute minimum. Therefore, this type
additionally provides PartialEq and Eq implementations that compare by
hash instead of by value. For this to be correct, your hash implementation
must feed all information relevant to the PartialEq impl to the
hasher.
Implementations§
Trait Implementations§
source§impl<T: ?Sized> PartialEq for Prehashed<T>
impl<T: ?Sized> PartialEq for Prehashed<T>
source§impl<T: PartialOrd + ?Sized> PartialOrd for Prehashed<T>
impl<T: PartialOrd + ?Sized> PartialOrd for Prehashed<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read more