pub struct LruCache<K, V, S = DefaultHashBuilder> { /* private fields */ }
Implementations§
Source§impl<K: Eq + Hash, V> LruCache<K, V>
impl<K: Eq + Hash, V> LruCache<K, V>
pub fn new(capacity: usize) -> Self
Sourcepub fn new_unbounded() -> Self
pub fn new_unbounded() -> Self
Create a new unbounded LruCache
that does not automatically evict entries.
A simple convenience method that is equivalent to LruCache::new(usize::MAX)
Source§impl<K, V, S> LruCache<K, V, S>
impl<K, V, S> LruCache<K, V, S>
pub fn with_hasher(capacity: usize, hash_builder: S) -> Self
pub fn capacity(&self) -> usize
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn clear(&mut self)
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V> ⓘ
pub fn drain(&mut self) -> Drain<'_, K, V> ⓘ
Source§impl<K: Eq + Hash, V, S> LruCache<K, V, S>where
S: BuildHasher,
impl<K: Eq + Hash, V, S> LruCache<K, V, S>where
S: BuildHasher,
pub fn contains_key<Q>(&self, key: &Q) -> bool
Sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
pub fn insert(&mut self, k: K, v: V) -> Option<V>
Insert a new value into the LruCache
.
If necessary, will remove the value at the front of the LRU list to make room.
Sourcepub fn peek<Q>(&self, k: &Q) -> Option<&V>
pub fn peek<Q>(&self, k: &Q) -> Option<&V>
Get the value for the given key, without marking the value as recently used and moving it to the back of the LRU list.
Sourcepub fn peek_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn peek_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Get the value for the given key mutably, without marking the value as recently used and moving it to the back of the LRU list.
Sourcepub fn get<Q>(&mut self, k: &Q) -> Option<&V>
pub fn get<Q>(&mut self, k: &Q) -> Option<&V>
Retrieve the given key, marking it as recently used and moving it to the back of the LRU list.
Sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
Retrieve the given key, marking it as recently used and moving it to the back of the LRU list.
Sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>
If the returned entry is vacant, it will always have room to insert a single value. By using the entry API, you can exceed the configured capacity by 1.
The returned entry is not automatically moved to the back of the LRU list. By calling
Entry::to_back
/ Entry::to_front
you can manually control the position of this entry in
the LRU list.
Sourcepub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
The constructed raw entry is never automatically moved to the back of the LRU list. By
calling Entry::to_back
/ Entry::to_front
you can manually control the position of this
entry in the LRU list.
Sourcepub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
If the constructed raw entry is vacant, it will always have room to insert a single value. By using the raw entry API, you can exceed the configured capacity by 1.
The constructed raw entry is never automatically moved to the back of the LRU list. By
calling Entry::to_back
/ Entry::to_front
you can manually control the position of this
entry in the LRU list.
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
Sourcepub fn set_capacity(&mut self, capacity: usize)
pub fn set_capacity(&mut self, capacity: usize)
Set the new cache capacity for the LruCache
.
If there are more entries in the LruCache
than the new capacity will allow, they are
removed.
Sourcepub fn remove_lru(&mut self) -> Option<(K, V)>
pub fn remove_lru(&mut self) -> Option<(K, V)>
Remove the least recently used entry and return it.
If the LruCache
is empty this will return None.
Trait Implementations§
Source§impl<K: Eq + Hash, V, S: BuildHasher> Extend<(K, V)> for LruCache<K, V, S>
impl<K: Eq + Hash, V, S: BuildHasher> Extend<(K, V)> for LruCache<K, V, S>
Source§fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)