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>>>
impl WeakList<Lazy<HashSet<usize>>>
pub const fn new() -> Self
pub fn realloc_hashset_if_needed_no_alloc( &mut self, bigger_hashset: Option<&mut AllocHashSet>, )
Sourcepub fn hashset_capacity(&self) -> usize
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>
impl<S: WeakListNodeSet> WeakList<S>
Sourcepub fn push_front<T: Send + Sync + 'static>(&mut self, elem: T) -> WeakRef<T>
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.
Sourcepub fn push_front_no_alloc<T: Send + Sync + 'static>(
&mut self,
elem: T,
memory: AllocMem<T>,
) -> WeakRef<T>
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.
Sourcepub fn pop_back(&mut self) -> Option<Arc<dyn Any + Send + Sync + 'static>>
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.
Sourcepub fn pop_lru(&mut self) -> Option<Arc<dyn Any + Send + Sync + 'static>>
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 ArcRef
s referencing it.
Sourcepub fn remove_unreachable(
&mut self,
) -> Vec<Arc<dyn Any + Send + Sync + 'static>>
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.
Sourcepub fn remove_unreachable_into_buf(
&mut self,
buf: &mut [Option<Arc<dyn Any + Send + Sync + 'static>>],
) -> usize
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.
Sourcepub fn remove_unreachable_into_f<F>(&mut self, f: F)
pub fn remove_unreachable_into_f<F>(&mut self, f: F)
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.