pub struct LruQueue<K: Eq + Hash + Clone, V> { /* private fields */ }
Expand description
Provides a Least Recently Used queue with unbounded capacity.
§Examples
use datafusion_execution::cache::lru_queue::LruQueue;
let mut lru_queue: LruQueue<i32, i32> = LruQueue::new();
lru_queue.put(1, 10);
lru_queue.put(2, 20);
lru_queue.put(3, 30);
assert_eq!(lru_queue.get(&2), Some(&20));
assert_eq!(lru_queue.pop(), Some((1, 10)));
assert_eq!(lru_queue.pop(), Some((3, 30)));
assert_eq!(lru_queue.pop(), Some((2, 20)));
assert_eq!(lru_queue.pop(), None);
Implementations§
Source§impl<K: Eq + Hash + Clone, V> LruQueue<K, V>
impl<K: Eq + Hash + Clone, V> LruQueue<K, V>
pub fn new() -> Self
Sourcepub fn get(&mut self, key: &K) -> Option<&V>
pub fn get(&mut self, key: &K) -> Option<&V>
Returns a reference to value mapped by key
, if it exists.
If the entry exists, it becomes the most recently used.
Sourcepub fn peek(&self, key: &K) -> Option<&V>
pub fn peek(&self, key: &K) -> Option<&V>
Returns a reference to value mapped by key
, if it exists.
Does not affect the queue order.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Checks whether there is an entry with key key
in the queue.
Does not affect the queue order.
Sourcepub fn put(&mut self, key: K, value: V) -> Option<V>
pub fn put(&mut self, key: K, value: V) -> Option<V>
Inserts an entry in the queue, becoming the most recently used. If the entry already exists, returns the previous value.
Sourcepub fn pop(&mut self) -> Option<(K, V)>
pub fn pop(&mut self) -> Option<(K, V)>
Removes and returns the least recently used value.
Returns None
if the queue is empty.
Sourcepub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Removes a specific entry from the queue, if it exists.
Sourcepub fn list_entries(&self) -> HashMap<&K, &V>
pub fn list_entries(&self) -> HashMap<&K, &V>
Returns a reference to the entries currently in the queue.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> Freeze for LruQueue<K, V>
impl<K, V> !RefUnwindSafe for LruQueue<K, V>
impl<K, V> Send for LruQueue<K, V>
impl<K, V> Sync for LruQueue<K, V>
impl<K, V> Unpin for LruQueue<K, V>
impl<K, V> !UnwindSafe for LruQueue<K, V>
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
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more