[][src]Struct clru::CLruCache

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

An LRU cache with constant time operations.

Implementations

impl<K, V, S> CLruCache<K, V, S>[src]

pub fn iter(&self) -> CLruCacheIter<'_, K, V>

Notable traits for CLruCacheIter<'a, K, V>

impl<'a, K, V> Iterator for CLruCacheIter<'a, K, V> type Item = (&'a K, &'a V);
[src]

Returns an iterator visiting all entries in order. The iterator element type is (&'a K, &'a V).

pub fn iter_mut(&mut self) -> CLruCacheIterMut<'_, K, V>

Notable traits for CLruCacheIterMut<'a, K, V>

impl<'a, K, V> Iterator for CLruCacheIterMut<'a, K, V> type Item = (&'a K, &'a mut V);
[src]

Returns an iterator visiting all entries in order, giving a mutable reference on V. The iterator element type is (&'a K, &'a mut V).

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

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

Creates a new LRU Cache that holds at most capacity items.

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

pub fn with_hasher(capacity: usize, hash_builder: S) -> Self[src]

Creates a new LRU Cache that holds at most capacity items and uses the provided hash builder to hash keys.

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

Returns the number of key-value pairs that are currently in the the cache.

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

Returns the maximum number of key-value pairs the cache can hold.

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

Returns a bool indicating whether the cache is empty or not.

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

Returns a bool indicating whether the cache is full or not.

pub fn front(&self) -> Option<(&K, &V)>[src]

Returns the value corresponding to the most recently used item or None if the cache is empty. Like peek, font does not update the LRU list so the item's position will be unchanged.

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

Returns the value corresponding to the most recently used item or None if the cache is empty. Like peek, font does not update the LRU list so the item's position will be unchanged.

pub fn back(&self) -> Option<(&K, &V)>[src]

Returns the value corresponding to the least recently used item or None if the cache is empty. Like peek, back does not update the LRU list so the item's position will be unchanged.

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

Returns the value corresponding to the least recently used item or None if the cache is empty. Like peek, back does not update the LRU list so the item's position will be unchanged.

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

Puts a key-value pair into cache. If the key already exists in the cache, then it updates the key's value and returns the old value. Otherwise, None is returned.

pub fn get<Q: ?Sized>(&mut self, key: &Q) -> Option<&V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Returns a reference to the value of the key in the cache or None if it is not present in the cache. Moves the key to the head of the LRU list if it exists.

pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Returns a mutable reference to the value of the key in the cache or None if it is not present in the cache. Moves the key to the head of the LRU list if it exists.

pub fn pop<Q: ?Sized>(&mut self, key: &Q) -> Option<V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Removes and returns the value corresponding to the key from the cache or None if it does not exist.

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

Removes and returns the key and value corresponding to the most recently used item or None if the cache is empty.

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

Removes and returns the key and value corresponding to the least recently used item or None if the cache is empty.

pub fn peek<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Returns a reference to the value corresponding to the key in the cache or None if it is not present in the cache. Unlike get, peek does not update the LRU list so the key's position will be unchanged.

pub fn peek_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut V> where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Returns a mutable reference to the value corresponding to the key in the cache or None if it is not present in the cache. Unlike get_mut, peek_mut does not update the LRU list so the key's position will be unchanged.

pub fn contains<Q: ?Sized>(&mut self, key: &Q) -> bool where
    K: Borrow<Q>,
    Q: Hash + Eq
[src]

Returns a bool indicating whether the given key is in the cache. Does not update the LRU list.

pub fn clear(&mut self)[src]

Clears the contents of the cache.

pub fn resize(&mut self, capacity: usize)[src]

Resizes the cache. If the new capacity is smaller than the size of the current cache any entries past the new capacity are discarded.

pub fn retain<F>(&mut self, f: F) where
    F: FnMut(&K, &mut V) -> bool
[src]

Retains only the elements specified by the predicate. In other words, remove all pairs (k, v) such that f(&k,&mut v) returns false.

Trait Implementations

impl<'a, K, V, S> IntoIterator for &'a CLruCache<K, V, S>[src]

type Item = (&'a K, &'a V)

The type of the elements being iterated over.

type IntoIter = CLruCacheIter<'a, K, V>

Which kind of iterator are we turning this into?

impl<'a, K, V, S> IntoIterator for &'a mut CLruCache<K, V, S>[src]

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.

type IntoIter = CLruCacheIterMut<'a, K, V>

Which kind of iterator are we turning this into?

impl<K: Eq + Hash, V, S: BuildHasher> IntoIterator for CLruCache<K, V, S>[src]

type Item = (K, V)

The type of the elements being iterated over.

type IntoIter = CLruCacheIntoIter<K, V, S>

Which kind of iterator are we turning this into?

fn into_iter(self) -> CLruCacheIntoIter<K, V, S>

Notable traits for CLruCacheIntoIter<K, V, S>

impl<K: Eq + Hash, V, S: BuildHasher> Iterator for CLruCacheIntoIter<K, V, S> type Item = (K, V);
[src]

Consumes the cache into an iterator yielding elements by value.

Auto Trait Implementations

impl<K, V, S = RandomState> !RefUnwindSafe for CLruCache<K, V, S>

impl<K, V, S = RandomState> !Send for CLruCache<K, V, S>

impl<K, V, S = RandomState> !Sync for CLruCache<K, V, S>

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

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

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<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.