pub struct SlabArena<T> { /* private fields */ }Expand description
An arena with O(1) deallocation via a free list.
Freed slots are tracked and reused on the next allocation.
Implementations§
Source§impl<T> SlabArena<T>
impl<T> SlabArena<T>
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a slab arena with the given initial capacity.
Sourcepub fn alloc(&mut self, value: T) -> Idx<T>
pub fn alloc(&mut self, value: T) -> Idx<T>
Allocate a value, reusing a freed slot if available.
Sourcepub fn free(&mut self, idx: Idx<T>) -> Option<T>
pub fn free(&mut self, idx: Idx<T>) -> Option<T>
Free the value at idx, returning it.
Returns None if the slot was already free.
Sourcepub fn get(&self, idx: Idx<T>) -> Option<&T>
pub fn get(&self, idx: Idx<T>) -> Option<&T>
Get a reference to the value at idx.
Returns None if the slot is free.
Sourcepub fn get_mut(&mut self, idx: Idx<T>) -> Option<&mut T>
pub fn get_mut(&mut self, idx: Idx<T>) -> Option<&mut T>
Get a mutable reference to the value at idx.
Sourcepub fn capacity_slots(&self) -> usize
pub fn capacity_slots(&self) -> usize
Total number of slots (including free ones).
Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of slots on the free list.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for SlabArena<T>
impl<T> RefUnwindSafe for SlabArena<T>where
T: RefUnwindSafe,
impl<T> Send for SlabArena<T>where
T: Send,
impl<T> Sync for SlabArena<T>where
T: Sync,
impl<T> Unpin for SlabArena<T>where
T: Unpin,
impl<T> UnsafeUnpin for SlabArena<T>
impl<T> UnwindSafe for SlabArena<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more