Struct uluru::LRUCache
[−]
[src]
pub struct LRUCache<A: Array> { /* fields omitted */ }
A LRU cache using a statically-sized array for storage.
LRUCache
uses a fixed-capacity array for storage. It provides O(1)
insertion, and O(n)
lookup.
All items are stored inline within the LRUCache
, so it does not impose any heap allocation or
indirection. A linked list is used to record the cache order, so the items themselves do not
need to be moved when the order changes. (This is important for speed if the items are large.)
Methods
impl<T, A: Array<Item = Entry<T>>> LRUCache<A>
[src]
pub fn num_entries(&self) -> usize
[src]
Returns the number of elements in the cache.
pub fn touch(&mut self, idx: CacheIndex)
[src]
Touch a given entry, putting it first in the list.
pub fn front(&self) -> Option<&T>
[src]
Returns the front entry in the list (most recently used).
pub fn front_mut(&mut self) -> Option<&mut T>
[src]
Returns a mutable reference to the front entry in the list (most recently used).
ⓘImportant traits for LRUCacheIterator<'a, A>pub fn iter(&self) -> LRUCacheIterator<A>
[src]
Iterate over the contents of this cache, from more to less recently used.
ⓘImportant traits for LRUCacheMutIterator<'a, A>pub fn iter_mut(&mut self) -> LRUCacheMutIterator<A>
[src]
Iterate mutably over the contents of this cache.
pub fn lookup<F, R>(&mut self, test_one: F) -> Option<R> where
F: FnMut(&mut T) -> Option<R>,
[src]
F: FnMut(&mut T) -> Option<R>,
Performs a lookup on the cache with the given test routine. Touches the result on a hit.
pub fn find<F>(&mut self, pred: F) -> Option<&mut T> where
F: FnMut(&T) -> bool,
[src]
F: FnMut(&T) -> bool,
Returns the first item in the cache that matches the given predicate. Touches the result on a hit.
pub fn insert(&mut self, val: T)
[src]
Insert a given key in the cache.
This item becomes the front (most-recently-used) item in the cache. If the cache is full, the back (least-recently-used) item will be removed.
pub fn evict_all(&mut self)
[src]
Evict all elements from the cache.