Struct fre::stats::ItemStats

source ·
pub struct ItemStats {
    pub item: String,
    pub num_accesses: i32,
    /* private fields */
}
Expand description

A representation of statistics for a single item

Fields§

§item: String§num_accesses: i32

Implementations§

source§

impl ItemStats

source

pub fn new(item: String, ref_time: f64, half_life: f64) -> ItemStats

Create a new item

source

pub fn cmp_score(&self, other: &ItemStats, method: SortMethod) -> Ordering

Compare the score of two items given a sort method

source

pub fn set_half_life(&mut self, half_life: f64)

Change the half life of the item, maintaining the same frecency

source

pub fn get_frecency(&self, current_time_secs: f64) -> f64

Calculate the frecency of the item

source

pub fn set_frecency(&mut self, new: f64)

source

pub fn update_frecency(&mut self, weight: f64)

update the frecency of the item by the given weight

source

pub fn update_num_accesses(&mut self, weight: i32)

Update the number of accesses of the item by the given weight

source

pub fn update_last_access(&mut self, time: f64)

Update the time the item was last accessed

source

pub fn reset_ref_time(&mut self, new_time: f64)

Reset the reference time and recalculate the last_accessed time

source

pub fn last_access(&self) -> f64

Timestamp (in nanoseconds since epoch) of the last access

Trait Implementations§

source§

impl Clone for ItemStats

source§

fn clone(&self) -> ItemStats

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl From<ItemStats> for ItemStatsSerializer

source§

fn from(stats: ItemStats) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.