LruQueue

Struct LruQueue 

Source
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>

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn pop(&mut self) -> Option<(K, V)>

Removes and returns the least recently used value. Returns None if the queue is empty.

Source

pub fn remove(&mut self, key: &K) -> Option<V>

Removes a specific entry from the queue, if it exists.

Source

pub fn len(&self) -> usize

Returns the number of entries in the queue.

Source

pub fn is_empty(&self) -> bool

Checks whether the queue has no items.

Source

pub fn clear(&mut self)

Removes all entries from the queue.

Source

pub fn list_entries(&self) -> HashMap<&K, &V>

Returns a reference to the entries currently in the queue.

Trait Implementations§

Source§

impl<K: Default + Eq + Hash + Clone, V: Default> Default for LruQueue<K, V>

Source§

fn default() -> LruQueue<K, V>

Returns the “default value” for a type. Read more

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>
where K: Send, V: Send,

§

impl<K, V> Sync for LruQueue<K, V>
where K: Sync + Send, V: Sync,

§

impl<K, V> Unpin for LruQueue<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> !UnwindSafe for LruQueue<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,