pub struct SmallLruCache<K, V, const N: usize, I: IndexType = u8, S = HeaplessBTreeLruCache<K, V, N, I>>where
S: AnyLruCache<K, V>,{ /* private fields */ }Expand description
A structure representing SmallLruCache.
This LRU cache limits its entries natively using a stack layout up to size N.
Beyond N, operations will cause the cache to spill transparently into a heap
allocated lru::LruCache.
Implementations§
Source§impl<K, V, const N: usize, I, S> SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> SmallLruCache<K, V, N, I, S>
Sourcepub fn capacity(&self) -> NonZeroUsize
pub fn capacity(&self) -> NonZeroUsize
Returns the maximum capacity of the cache.
Sourcepub fn get<Q>(&mut self, key: &Q) -> Option<&V>
pub fn get<Q>(&mut self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key, moving it to the MRU position.
Sourcepub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Returns a mutable reference to the value corresponding to the key, moving it to the MRU position.
Sourcepub fn peek<Q>(&self, key: &Q) -> Option<&V>
pub fn peek<Q>(&self, key: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key without updating the LRU state.
Sourcepub fn put(&mut self, key: K, value: V) -> Option<V>
pub fn put(&mut self, key: K, value: V) -> Option<V>
Pushes a key-value pair into the cache. If the key already exists, updates the value and returns it.
If the stack capacity N is exceeded during put, this will transparently allocate a lru::LruCache
and spill all elements to the heap.
Sourcepub fn is_on_stack(&self) -> bool
pub fn is_on_stack(&self) -> bool
Returns true if this cache is currently allocated entirely on the stack.
Sourcepub fn contains<Q>(&self, key: &Q) -> bool
pub fn contains<Q>(&self, key: &Q) -> bool
Returns true if the cache contains a value for the specified key.
Sourcepub fn push(&mut self, key: K, value: V) -> Option<(K, V)>
pub fn push(&mut self, key: K, value: V) -> Option<(K, V)>
Pushes a key-value pair into the cache. If the key already exists, updates the value. If pushing causes the capacity to be exceeded, returns the evicted LRU pair.
Sourcepub fn pop<Q>(&mut self, key: &Q) -> Option<V>
pub fn pop<Q>(&mut self, key: &Q) -> Option<V>
Removes and returns the value corresponding to the key from the cache.
Sourcepub fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
pub fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Removes and returns the key-value pair corresponding to the key from the cache.
Sourcepub fn pop_lru(&mut self) -> Option<(K, V)>
pub fn pop_lru(&mut self) -> Option<(K, V)>
Removes and returns the Least Recently Used (LRU) key-value pair.
Sourcepub fn promote<Q>(&mut self, key: &Q)
pub fn promote<Q>(&mut self, key: &Q)
Explictly promotes the corresponding key to the Most Recently Used (MRU) position.
Sourcepub fn demote<Q>(&mut self, key: &Q)
pub fn demote<Q>(&mut self, key: &Q)
Explicitly demotes the corresponding key to the Least Recently Used (LRU) position.
Sourcepub fn peek_lru(&self) -> Option<(&K, &V)>
pub fn peek_lru(&self) -> Option<(&K, &V)>
Returns references to the Least Recently Used (LRU) key-value pair without removing it.
Sourcepub fn resize(&mut self, cap: NonZeroUsize)
pub fn resize(&mut self, cap: NonZeroUsize)
Resizes the cache to a new maximum capacity.
If the new capacity exceeds the stack limit N, it transparently spills to the heap.
Sourcepub fn get_or_insert<F>(&mut self, key: K, f: F) -> &Vwhere
F: FnOnce() -> V,
pub fn get_or_insert<F>(&mut self, key: K, f: F) -> &Vwhere
F: FnOnce() -> V,
Returns a reference to the value for the key, or inserts a new one.
Sourcepub fn get_or_insert_mut<F>(&mut self, key: K, f: F) -> &mut Vwhere
F: FnOnce() -> V,
pub fn get_or_insert_mut<F>(&mut self, key: K, f: F) -> &mut Vwhere
F: FnOnce() -> V,
Returns a mutable reference to the value for the key, or inserts a new one.
Sourcepub fn iter(&self) -> Iter<'_, K, V, N, I, S> ⓘwhere
for<'a> S: LruIteratorSupport<'a, K, V>,
pub fn iter(&self) -> Iter<'_, K, V, N, I, S> ⓘwhere
for<'a> S: LruIteratorSupport<'a, K, V>,
Returns an iterator over the elements.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V, N, I, S> ⓘwhere
for<'a> S: LruIteratorSupport<'a, K, V>,
pub fn iter_mut(&mut self) -> IterMut<'_, K, V, N, I, S> ⓘwhere
for<'a> S: LruIteratorSupport<'a, K, V>,
Returns an iterator over the elements.
Source§impl<K, V, const N: usize, I, S> SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> SmallLruCache<K, V, N, I, S>
Sourcepub fn new(cap: NonZeroUsize) -> Self
pub fn new(cap: NonZeroUsize) -> Self
Automatically generated documentation for this item.
Trait Implementations§
Source§impl<K, V, const N: usize, I, S> AnyLruCache<K, V> for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> AnyLruCache<K, V> for SmallLruCache<K, V, N, I, S>
Source§fn len(&self) -> usize
fn len(&self) -> usize
Source§fn cap(&self) -> NonZeroUsize
fn cap(&self) -> NonZeroUsize
Source§fn put(&mut self, key: K, value: V) -> Option<V>
fn put(&mut self, key: K, value: V) -> Option<V>
Source§fn put_with_cap(
&mut self,
key: K,
value: V,
cap: NonZeroUsize,
) -> (Option<V>, Result<(), (K, V)>)
fn put_with_cap( &mut self, key: K, value: V, cap: NonZeroUsize, ) -> (Option<V>, Result<(), (K, V)>)
(old_value, Result<(), (key, value)>). The result is an error if capacity is reached and the backend cannot grow.Source§fn get<Q>(&mut self, key: &Q) -> Option<&V>
fn get<Q>(&mut self, key: &Q) -> Option<&V>
Source§fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
Source§fn peek<Q>(&self, key: &Q) -> Option<&V>
fn peek<Q>(&self, key: &Q) -> Option<&V>
Source§fn pop_lru(&mut self) -> Option<(K, V)>
fn pop_lru(&mut self) -> Option<(K, V)>
Source§fn push(&mut self, key: K, value: V) -> Option<(K, V)>
fn push(&mut self, key: K, value: V) -> Option<(K, V)>
Source§fn pop<Q>(&mut self, key: &Q) -> Option<V>
fn pop<Q>(&mut self, key: &Q) -> Option<V>
Source§fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
fn pop_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
Source§impl<K, V, const N: usize, I, S> Clone for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> Clone for SmallLruCache<K, V, N, I, S>
Source§impl<K, V, const N: usize, I, S> Debug for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> Debug for SmallLruCache<K, V, N, I, S>
Source§impl<K: Hash + Eq + Ord + Clone, V, const N: usize, I: IndexType, S> Default for SmallLruCache<K, V, N, I, S>where
S: AnyLruCache<K, V> + Default,
impl<K: Hash + Eq + Ord + Clone, V, const N: usize, I: IndexType, S> Default for SmallLruCache<K, V, N, I, S>where
S: AnyLruCache<K, V> + Default,
Source§impl<K, V, const N: usize, I, S> Drop for SmallLruCache<K, V, N, I, S>where
I: IndexType,
S: AnyLruCache<K, V>,
impl<K, V, const N: usize, I, S> Drop for SmallLruCache<K, V, N, I, S>where
I: IndexType,
S: AnyLruCache<K, V>,
Source§impl<K, V, const N: usize, I, S> Extend<(K, V)> for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> Extend<(K, V)> for SmallLruCache<K, V, N, I, S>
Source§fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T)
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<K, V, const N: usize, I, S> FromIterator<(K, V)> for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> FromIterator<(K, V)> for SmallLruCache<K, V, N, I, S>
Source§impl<'a, K, V, const N: usize, I, S> IntoIterator for &'a SmallLruCache<K, V, N, I, S>where
K: Hash + Eq + Ord + Clone,
I: IndexType,
S: AnyLruCache<K, V> + for<'b> LruIteratorSupport<'b, K, V>,
impl<'a, K, V, const N: usize, I, S> IntoIterator for &'a SmallLruCache<K, V, N, I, S>where
K: Hash + Eq + Ord + Clone,
I: IndexType,
S: AnyLruCache<K, V> + for<'b> LruIteratorSupport<'b, K, V>,
Source§impl<'a, K, V, const N: usize, I, S> IntoIterator for &'a mut SmallLruCache<K, V, N, I, S>where
K: Hash + Eq + Ord + Clone,
I: IndexType,
S: AnyLruCache<K, V> + for<'b> LruIteratorSupport<'b, K, V>,
impl<'a, K, V, const N: usize, I, S> IntoIterator for &'a mut SmallLruCache<K, V, N, I, S>where
K: Hash + Eq + Ord + Clone,
I: IndexType,
S: AnyLruCache<K, V> + for<'b> LruIteratorSupport<'b, K, V>,
Source§impl<K, V, const N: usize, I, S> IntoIterator for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> IntoIterator for SmallLruCache<K, V, N, I, S>
Source§impl<'a, K, V, const N: usize, I, S> LruIteratorSupport<'a, K, V> for SmallLruCache<K, V, N, I, S>where
K: Hash + Eq + Ord + Clone + 'a,
V: 'a,
I: IndexType,
S: AnyLruCache<K, V> + for<'b> LruIteratorSupport<'b, K, V>,
impl<'a, K, V, const N: usize, I, S> LruIteratorSupport<'a, K, V> for SmallLruCache<K, V, N, I, S>where
K: Hash + Eq + Ord + Clone + 'a,
V: 'a,
I: IndexType,
S: AnyLruCache<K, V> + for<'b> LruIteratorSupport<'b, K, V>,
Auto Trait Implementations§
impl<K, V, const N: usize, I, S> Freeze for SmallLruCache<K, V, N, I, S>where
S: Freeze,
impl<K, V, const N: usize, I, S> RefUnwindSafe for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> Send for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> Sync for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> Unpin for SmallLruCache<K, V, N, I, S>
impl<K, V, const N: usize, I, S> UnsafeUnpin for SmallLruCache<K, V, N, I, S>where
S: UnsafeUnpin,
impl<K, V, const N: usize, I, S> UnwindSafe for SmallLruCache<K, V, N, I, 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§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.