Skip to main content

Crate cachedhash

Crate cachedhash 

Source
Expand description

For a type T, CachedHash<T> wraps T and implements Hash in a way that caches T’s hash value. This is useful when T is expensive to hash (for example if it contains a large vector) and you need to hash it multiple times with few modifications (for example by moving it between multiple HashSets).

Stored hash is invalidated whenever the stored value is accessed mutably (via DerefMut, AsMut, or explicitly via a provided associated function). In order for the hash to be invalidated correctly the stored type cannot use interior mutability in a way that affects the hash. If this is the case, you can use CachedHash::invalidate_hash to invalidate the hash manually.

To look up entries in a HashSet<CachedHash<T>> or HashMap<CachedHash<T>, V> by a &T without first wrapping it into a CachedHash, use CachedHashKey::from_ref.

Structs§

CachedHash
Deref wrapper around T, which caches the hash of T for efficient repeated hashing.
CachedHashKey
A borrowed-form lookup key for collections keyed on CachedHash<T, BH>.