Skip to main content

LruCache

Struct LruCache 

Source
pub struct LruCache { /* private fields */ }
Expand description

Simple LRU cache for text deduplication.

Maintains insertion order and evicts the oldest entry when capacity is reached. Note: Updating an existing key does NOT refresh its position (matches Go behavior).

§Example

use html_cleaning::dedup::LruCache;

let mut cache = LruCache::new(3);
cache.put("a", 1);
cache.put("b", 2);
assert_eq!(cache.get("a"), Some(1));
assert!(cache.has("b"));

Implementations§

Source§

impl LruCache

Source

pub fn new(max_size: usize) -> Self

Create new cache with specified capacity.

Source

pub fn get(&self, key: &str) -> Option<i32>

Get value for key.

Source

pub fn has(&self, key: &str) -> bool

Check if key exists.

Source

pub fn put(&mut self, key: &str, value: i32)

Store key-value pair, evicting oldest if at capacity.

Source

pub fn clear(&mut self)

Clear all entries.

Source

pub fn len(&self) -> usize

Get current size.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn remove(&mut self, key: &str)

Remove a specific key from the cache.

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