Skip to main content

BudgetLru

Struct BudgetLru 

Source
pub struct BudgetLru<K: Ord + Copy, V> {
    map: BTreeMap<K, Slot<V>>,
    order: BTreeMap<u64, K>,
    clock: u64,
    total: usize,
    limits: Limits,
}
Expand description

量の上限つきの、使った時が古い順に捨てる表。

Fields§

§map: BTreeMap<K, Slot<V>>§order: BTreeMap<u64, K>

使った時 → 鍵。最初の物がいちばん古い。

§clock: u64§total: usize§limits: Limits

Implementations§

Source§

impl<K: Ord + Copy, V> BudgetLru<K, V>

Source

pub const fn new(limits: Limits) -> Self

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn total_bytes(&self) -> usize

今入っている項目の量の合計(見積もり)。

Source

pub fn limits(&self) -> Limits

Source

fn next_clock(&mut self) -> u64

Source

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

引く。当たったら使った時を今にする。

Source

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

使った時を変えずに見る(試験・統計用)。

Source

fn remove_slot(&mut self, key: &K) -> Option<Slot<V>>

Source

fn evict_oldest(&mut self) -> Option<usize>

いちばん古い項目を捨てる。捨てた量を返す。

Source

pub fn insert( &mut self, key: K, value: V, bytes: usize, group: u8, ) -> InsertOutcome

入れる。同じ鍵があれば置き換える。全体の量・項目の数の上限に収まるまで古い順に捨ててから入れる。

Source

pub fn retain(&mut self, keep: impl FnMut(u8, &V) -> bool) -> (usize, usize)

keep(組, 値) が偽の項目を捨てる。捨てた項目の数と量を返す。

Source

pub fn clear(&mut self)

全部捨てる。

Auto Trait Implementations§

§

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

§

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

§

impl<K, V> Send for BudgetLru<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for BudgetLru<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for BudgetLru<K, V>

§

impl<K, V> UnsafeUnpin for BudgetLru<K, V>

§

impl<K, V> UnwindSafe for BudgetLru<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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.