pub struct PECache<K, V, E, P> { /* private fields */ }

Implementations§

source§

impl<K: Clone + Hash + Ord, V: Clone + Eq + Hash + PartialEq, E: Clone + Ord + Eq, P: Clone + Ord> PECache<K, V, E, P>

source

pub fn new() -> Self

Creates a new PE Cache.

Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();
source

pub fn set(&mut self, key: K, value: V, expiry: E, priority: P)

Add a new item to the cache or override the existing one if present in O(1) time.

Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();
    let (key, value, expiry, priority) = (
        String::from("key"),
        String::from("value"), 1, 1);
new_cache.set(key.clone(),value.clone(), expiry, priority);
source

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

Gat the value associated with the key if present or None if not in O(1) time.

Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();

// the get operation
let extracted_value = new_cache.get("key".to_string());
source

pub fn evict(&mut self, barrier: E)

Evict 1 element following this policy if at least one element is present in O(1).

Policy:

  • If an expired item is available. Remove it. If multiple items have the same expiry, removing any one suffices.
  • If condition #1 can’t be satisfied, remove an item with the least priority.
  • If more than one item satisfies condition #2, remove the least recently used one.
  • Multiple items can have the same priority and expiry.
Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();


let extracted_value = new_cache.evict(10);
source

pub fn len(&self) -> usize

Return the Length of Cache items in O(1).

Examples
use priority_expiry_cache::PECache;
let mut new_cache:PECache<String,String,u32,u32>= PECache::new();


let cache_n_size = new_cache.len();

Auto Trait Implementations§

§

impl<K, V, E, P> RefUnwindSafe for PECache<K, V, E, P>

§

impl<K, V, E, P> Send for PECache<K, V, E, P>
where E: Send, K: Send, P: Send, V: Send,

§

impl<K, V, E, P> Sync for PECache<K, V, E, P>
where E: Sync, K: Sync, P: Sync, V: Sync,

§

impl<K, V, E, P> Unpin for PECache<K, V, E, P>
where E: Unpin, K: Unpin, P: Unpin, V: Unpin,

§

impl<K, V, E, P> UnwindSafe for PECache<K, V, E, P>

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

§

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

§

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.