Struct WeakList

Source
pub struct WeakList<S: WeakListNodeSet> { /* private fields */ }
Expand description

Doubly linked, heterogeneous, list of Arc-like nodes that functions as a least recently used cache.

Implementations§

Source§

impl WeakList<Lazy<HashSet<usize>>>

Source

pub const fn new() -> Self

Source

pub fn realloc_hashset_if_needed_no_alloc( &mut self, bigger_hashset: Option<&mut AllocHashSet>, )

Source

pub fn hashset_capacity(&self) -> usize

Returns the capacity of the hashset used to keep track of the active nodes. This capacity can be used to ensure that the AllocHashSet::with_capacity passed to push_front_no_alloc has a greater capacity.

Source§

impl<S: WeakListNodeSet> WeakList<S>

Source

pub fn push_front<T: Send + Sync + 'static>(&mut self, elem: T) -> WeakRef<T>

Push element to the front of the list. This makes this new element the most recently used.

Returns a WeakRef<T> that can be upgraded to an ArcRef<T>, similarly to the Weak/Arc std types.

Source

pub fn push_front_no_alloc<T: Send + Sync + 'static>( &mut self, elem: T, memory: AllocMem<T>, ) -> WeakRef<T>

Same as push_front, but does not allocate. The user is expected to pass AllocMem::default() and AllocHashSet::with_capacity(cap) as arguments.

Source

pub fn pop_back(&mut self) -> Option<Arc<dyn Any + Send + Sync + 'static>>

Remove the least recently used element. This does not check if that element is being currently used, so prefer using pop_lru instead.

Source

pub fn pop_lru(&mut self) -> Option<Arc<dyn Any + Send + Sync + 'static>>

Remove the least recently used element that is not currently being used: it does not have any active ArcRefs referencing it.

Source

pub fn remove_unreachable( &mut self, ) -> Vec<Arc<dyn Any + Send + Sync + 'static>>

Remove all the unreachable elements that do not have any WeakRef or ArcRef, so they will never be used again. Returns a Vec of the removed elements.

Source

pub fn remove_unreachable_into_buf( &mut self, buf: &mut [Option<Arc<dyn Any + Send + Sync + 'static>>], ) -> usize

Same as remove_all_unreachable, but insert the removed elements into the provided buffer. This can be used to manually deallocate the elements later if needed, and also if it is important to avoid allocations.

Note: this function returns immediately if the buffer fills up, so if the returned length is equal to the buffer size it means that there may still be some unreachable elements left.

Source

pub fn remove_unreachable_into_f<F>(&mut self, f: F)
where F: FnMut(Arc<dyn Any + Send + Sync + 'static>) -> ControlFlow<()>,

Same as remove_all_unreachable, but pass ownership of the removed element to the provided callback. This can be used to manually deallocate the elements later if needed.

Source

pub fn remove<T>(&mut self, weak_ref: &WeakRef<T>) -> Option<ArcRef<T>>

Remove an element from the list.

Source

pub fn clear(&mut self)

Remove all the elements from the list, regardless of if they are being actively used or not.

Trait Implementations§

Source§

impl<S: Default + WeakListNodeSet> Default for WeakList<S>

Source§

fn default() -> Self

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

impl<S: WeakListNodeSet> Drop for WeakList<S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<S: Send + WeakListNodeSet> Send for WeakList<S>

Source§

impl<S: Sync + WeakListNodeSet> Sync for WeakList<S>

Auto Trait Implementations§

§

impl<S> Freeze for WeakList<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for WeakList<S>
where S: RefUnwindSafe,

§

impl<S> Unpin for WeakList<S>
where S: Unpin,

§

impl<S> UnwindSafe for WeakList<S>
where S: 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<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.