PECache

Struct PECache 

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

Implementations§

Source§

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

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, priority: P, expiry: E)

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, priority, expiry) = (
        String::from("key"),
        String::from("value"), 1, 1);
new_cache.set(key.clone(),value.clone(), priority, expiry);
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, P, E> Freeze for PECache<K, V, P, E>

§

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

§

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

§

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

§

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

§

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

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.