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
)source§impl<'a, K, V, S> IntoIterator for &'a LruCache<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a LruCache<K, V, S>
source§impl<'a, K, V, S> IntoIterator for &'a mut LruCache<K, V, S>
impl<'a, K, V, S> IntoIterator for &'a mut LruCache<K, V, S>
Auto Trait Implementations§
impl<K, V, S> Freeze for LruCache<K, V, S>where
S: Freeze,
impl<K, V, S> RefUnwindSafe for LruCache<K, V, S>
impl<K, V, S> Send for LruCache<K, V, S>
impl<K, V, S> Sync for LruCache<K, V, S>
impl<K, V, S> Unpin for LruCache<K, V, S>where
S: Unpin,
impl<K, V, S> UnwindSafe for LruCache<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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)