ExpiringSet

Struct ExpiringSet 

Source
pub struct ExpiringSet<K>(/* private fields */);
Expand description

A set version of ExpiringMap. Sets V to ()

Implementations§

Source§

impl<K: PartialEq + Eq + Hash> ExpiringSet<K>

Source

pub fn new() -> Self

Create a new ExpiringSet

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new ExpiringSet with the specified capacity

Source

pub fn insert(&mut self, key: K, ttl: Duration) -> bool

Returns true if the set contains this value

Source

pub fn contains<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

Returns true if the set contains this value

Source

pub fn take<Q>(&mut self, key: &Q) -> Option<K>
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

If it exists and has not expired, remove and return the value at this key

Source

pub fn shrink_to_fit(&mut self)

Shrink the set to the minimum allowable size in accordance with the resize policy

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrink the set to the minimum of the minimum allowable size and the min_capacity in accordance with the resize policy

Methods from Deref<Target = ExpiringMap<K, ()>>§

Source

pub fn vacuum(&mut self)

Shrinks the hashmap based on entries that should no longer be contained. This is O(n).

Source

pub fn vacuum_if_needed(&mut self)

execute a vacuum if the map has grown by more than 1.5 times

Source

pub fn get_meta<Q>(&self, key: &Q) -> Option<&ExpiryValue<V>>
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

If the value exists and has not expired, return its expiry data

Source

pub fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

If the value exists and has not expired, return it

Source

pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

If a key exists for this value, get both the key and value if it is not expired

Source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

Get a mutable reference to the value pointed to by a key, if it is not expired

Source

pub fn insert( &mut self, key: K, value: V, ttl: Duration, ) -> Option<ExpiryValue<V>>

Insert a value into the map, returning the old value if it has not expired and existed

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

If this key exists and is not expired, returns true

Source

pub fn remove<Q>(&mut self, key: &Q) -> bool
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

Remove an item from the map. If it exists and has not expired, return true

Source

pub fn last_size(&self) -> usize

Return the size the map was last time it was vacuumed

Source

pub fn len(&self) -> usize

Return the number of items within the map

Source

pub fn is_empty(&self) -> bool

Return true if the Self::len is 0

Source

pub fn capacity(&self) -> usize

Return the capacity of the internal map

Source

pub fn reserve(&mut self, addtional: usize)

Reserve at least a certain capacity on the internal map

Source

pub fn shrink_to_fit(&mut self)

Remove all of the expired entries and shrink the map to the minimum allowable size in accordance with the resize policy

Source

pub fn shrink_to(&mut self, min_capacity: usize)

Remove all of the expired entries and shrink the map to the minimum of the minimum allowable size and the min_capacity in accordance with the resize policy

Source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: ?Sized + Hash + Eq,

Removes a key from the map, returning the stored key and value if the key was previously in the map.

Trait Implementations§

Source§

impl<K: Debug> Debug for ExpiringSet<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: PartialEq + Eq + Hash> Default for ExpiringSet<K>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K> Deref for ExpiringSet<K>

Source§

type Target = ExpiringMap<K, ()>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<K> DerefMut for ExpiringSet<K>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<K> Freeze for ExpiringSet<K>

§

impl<K> RefUnwindSafe for ExpiringSet<K>
where K: RefUnwindSafe,

§

impl<K> Send for ExpiringSet<K>
where K: Send,

§

impl<K> Sync for ExpiringSet<K>
where K: Sync,

§

impl<K> Unpin for ExpiringSet<K>
where K: Unpin,

§

impl<K> UnwindSafe for ExpiringSet<K>
where K: UnwindSafe,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.