Struct weight_cache::WeightCache[][src]

pub struct WeightCache<K, V, S = RandomState> { /* fields omitted */ }

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

impl<K: Hash + Eq, V: Weighable> WeightCache<K, V>[src]

pub fn new(capacity: NonZeroUsize) -> Self[src]

impl<K: Hash + Eq, V: Weighable, S: BuildHasher> WeightCache<K, V, S>[src]

pub fn with_hasher(capacity: NonZeroUsize, hasher: S) -> Self[src]

Create a WeightCache with a custom hasher.

pub fn get(&mut self, k: &K) -> Option<&V>[src]

Returns a reference to the value corresponding to the given key, if it exists.

pub fn len(&self) -> usize[src]

Returns the number of key-value pairs in the cache.

pub fn is_empty(&self) -> bool[src]

Returns true if the cache contains no key-value pairs.

pub fn put(&mut self, key: K, value: V) -> Result<(), ValueTooBigError>[src]

Inserts a key-value pair into the cache. Returns an error if the value is bigger than the cache’s configured max size.

impl<K: Hash + Eq + 'static, V: Weighable + 'static, S: BuildHasher> WeightCache<K, V, S>[src]

pub fn consume(self) -> Box<dyn Iterator<Item = (K, V)> + 'static>[src]

Returns an iterator over the cache’s key-value pairs in least- to most-recently-used order consuming the cache.

Trait Implementations

impl<K, V, S> Debug for WeightCache<K, V, S>[src]

impl<K: Hash + Eq, V: Weighable> Default for WeightCache<K, V>[src]

Auto Trait Implementations

impl<K, V, S> RefUnwindSafe for WeightCache<K, V, S> where
    K: RefUnwindSafe,
    S: RefUnwindSafe,
    V: RefUnwindSafe

impl<K, V, S> Send for WeightCache<K, V, S> where
    K: Send,
    S: Send,
    V: Send

impl<K, V, S> Sync for WeightCache<K, V, S> where
    K: Sync,
    S: Sync,
    V: Sync

impl<K, V, S> Unpin for WeightCache<K, V, S> where
    S: Unpin

impl<K, V, S> UnwindSafe for WeightCache<K, V, S> where
    K: RefUnwindSafe,
    S: UnwindSafe,
    V: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.