pub struct WeightCache<K, V, S = RandomState> { /* private fields */ }Expand description
A cache that holds a limited number of key-value pairs. When the capacity of the cache is exceeded, the least-recently-used (where “used” means a look-up or putting the pair into the cache) pairs are automatically removed until the size limit is met again.
Implementations§
Source§impl<K: Hash + Eq, V: Weighable> WeightCache<K, V>
impl<K: Hash + Eq, V: Weighable> WeightCache<K, V>
pub fn new(capacity: NonZeroUsize) -> Self
Source§impl<K: Hash + Eq, V: Weighable, S: BuildHasher> WeightCache<K, V, S>
impl<K: Hash + Eq, V: Weighable, S: BuildHasher> WeightCache<K, V, S>
Sourcepub fn with_hasher(capacity: NonZeroUsize, hasher: S) -> Self
pub fn with_hasher(capacity: NonZeroUsize, hasher: S) -> Self
Create a WeightCache with a custom hasher.
Sourcepub fn get(&mut self, k: &K) -> Option<&V>
pub fn get(&mut self, k: &K) -> Option<&V>
Returns a reference to the value corresponding to the given key, if it exists.
Sourcepub fn put(&mut self, key: K, value: V) -> Result<(), ValueTooBigError>
pub fn put(&mut self, key: K, value: V) -> Result<(), ValueTooBigError>
Inserts a key-value pair into the cache. Returns an error if the value is bigger than the cache’s configured max size.
Trait Implementations§
Source§impl<K, V, S> Debug for WeightCache<K, V, S>
impl<K, V, S> Debug for WeightCache<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for WeightCache<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for WeightCache<K, V, S>
impl<K, V, S> Send for WeightCache<K, V, S>
impl<K, V, S> Sync for WeightCache<K, V, S>
impl<K, V, S> Unpin for WeightCache<K, V, S>where
S: Unpin,
impl<K, V, S> UnwindSafe for WeightCache<K, V, 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