#hashing #hash #cache #hash-values #performance #wrapper

cachedhash

Wrapper for values that caches their hash

3 unstable releases

0.2.0 Feb 14, 2024
0.1.2 Oct 8, 2022
0.1.1 Oct 4, 2022
0.1.0 Oct 4, 2022

#116 in Caching

Download history 1977/week @ 2024-07-21 3492/week @ 2024-07-28 2538/week @ 2024-08-04 1970/week @ 2024-08-11 2279/week @ 2024-08-18 2226/week @ 2024-08-25 2215/week @ 2024-09-01 2573/week @ 2024-09-08 1495/week @ 2024-09-15 2722/week @ 2024-09-22 1060/week @ 2024-09-29 1969/week @ 2024-10-06 2396/week @ 2024-10-13 1510/week @ 2024-10-20 884/week @ 2024-10-27 2376/week @ 2024-11-03

7,313 downloads per month

MIT/Apache

22KB
348 lines

CachedHash

Build Status Crates.io Docs.rs

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, BorrowMut 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.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps