pub struct HashCache<'f, I, O, S = RandomState>where
I: Eq + Hash,{ /* private fields */ }Expand description
A cache for a function which uses a HashMap.
The cache takes ownership of all inputs, but only passes a reference to the function, allowing it to store the input in the cache without any copies or clones.
The requirements for a HashMap must be met,
specifically the keys must implement Eq and
Hash, and the following propery must hold:
k1 == k2 -> hash(k1) == hash(k2)
Implementations§
source§impl<'f, I, O> HashCache<'f, I, O, RandomState>where
I: Eq + Hash,
impl<'f, I, O> HashCache<'f, I, O, RandomState>where I: Eq + Hash,
source§impl<'f, I, O, S> HashCache<'f, I, O, S>where
I: Eq + Hash,
S: BuildHasher,
impl<'f, I, O, S> HashCache<'f, I, O, S>where I: Eq + Hash, S: BuildHasher,
sourcepub fn with_hasher<F>(hash_builder: S, f: F) -> Selfwhere
F: Fn(&I) -> O + 'f + Send + Sync,
pub fn with_hasher<F>(hash_builder: S, f: F) -> Selfwhere F: Fn(&I) -> O + 'f + Send + Sync,
Create a HashCache which will use the given hash builder to hash keys.
See the documentation on HashMap::with_hasher for more details.
sourcepub fn recursive_with_hasher<F>(hash_builder: S, f: F) -> Selfwhere
F: Fn(&mut Self, &I) -> O + 'f + Send + Sync,
pub fn recursive_with_hasher<F>(hash_builder: S, f: F) -> Selfwhere F: Fn(&mut Self, &I) -> O + 'f + Send + Sync,
Create a recursive HashCache which will use the given hash builder to hash keys.
See the documentation on HashMap::with_hasher for more details.
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the cache, removing all key-value pairs. Keeps the allocated memory for reuse.
Trait Implementations§
source§impl<'f, I, O, S> FnCache<I, O> for HashCache<'f, I, O, S>where
I: Eq + Hash,
S: BuildHasher,
impl<'f, I, O, S> FnCache<I, O> for HashCache<'f, I, O, S>where I: Eq + Hash, S: BuildHasher,
source§impl<'f, I, O, S> FnCacheMany<I, O> for HashCache<'f, I, O, S>where
I: Eq + Hash + Clone,
S: BuildHasher,
impl<'f, I, O, S> FnCacheMany<I, O> for HashCache<'f, I, O, S>where I: Eq + Hash + Clone, S: BuildHasher,
Auto Trait Implementations§
impl<'f, I, O, S = RandomState> !RefUnwindSafe for HashCache<'f, I, O, S>
impl<'f, I, O, S> Send for HashCache<'f, I, O, S>where I: Send, O: Send, S: Send,
impl<'f, I, O, S> Sync for HashCache<'f, I, O, S>where I: Sync, O: Sync, S: Sync,
impl<'f, I, O, S> Unpin for HashCache<'f, I, O, S>where I: Unpin, O: Unpin, S: Unpin,
impl<'f, I, O, S = RandomState> !UnwindSafe for HashCache<'f, I, O, S>
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