Struct SieveCache

Source
pub struct SieveCache<K: Eq + Hash + Clone, V> { /* private fields */ }
Expand description

A cache based on the SIEVE eviction algorithm.

Implementations§

Source§

impl<K: Eq + Hash + Clone, V> SieveCache<K, V>

Source

pub fn new(capacity: usize) -> Result<Self, &'static str>

Create a new cache with the given capacity.

Source

pub fn capacity(&self) -> usize

Return the capacity of the cache.

Source

pub fn len(&self) -> usize

Return the number of cached values.

Source

pub fn is_empty(&self) -> bool

Return true when no values are currently cached.

Source

pub fn contains_key<Q>(&mut self, key: &Q) -> bool
where Q: Hash + Eq + ?Sized, K: Borrow<Q>,

Return true if there is a value in the cache mapped to by key.

Source

pub fn get<Q>(&mut self, key: &Q) -> Option<&V>
where Q: Hash + Eq + ?Sized, K: Borrow<Q>,

Get an immutable reference to the value in the cache mapped to by key.

If no value exists for key, this returns None.

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where Q: Hash + Eq + ?Sized, K: Borrow<Q>,

Get a mutable reference to the value in the cache mapped to by key.

If no value exists for key, this returns None.

Source

pub fn insert(&mut self, key: K, value: V) -> bool

Map key to value in the cache, possibly evicting old entries.

This method returns true when this is a new entry, and false if an existing entry was updated.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where K: Borrow<Q>, Q: Eq + Hash + ?Sized,

Remove the cache entry mapped to by key.

This method returns the value removed from the cache. If key did not map to any value, then this returns None.

Trait Implementations§

Source§

impl<K: Eq + Hash + Clone, V> Send for SieveCache<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for SieveCache<K, V>

§

impl<K, V> RefUnwindSafe for SieveCache<K, V>

§

impl<K, V> !Sync for SieveCache<K, V>

§

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

§

impl<K, V> UnwindSafe for SieveCache<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, 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.