pub struct HiSlab<T: 'static> { /* private fields */ }Expand description
A slab allocator with O(1) insert and remove using hierarchical bitmaps.
HiSlab stores elements in a contiguous Vec and tracks free slots using
a 4-level bitmap hierarchy. This allows finding a free slot in constant time
regardless of fragmentation.
For tagging support, see TaggedHiSlab.
Implementations§
Source§impl<T> HiSlab<T>
impl<T> HiSlab<T>
Sourcepub fn new(initial_capacity: u32, virtual_capacity: u32) -> Result<Self, Error>
pub fn new(initial_capacity: u32, virtual_capacity: u32) -> Result<Self, Error>
Creates a new empty HiSlab.
virtual_capacity * size_of::<T>() octets sont réservés immédiatement en espace
virtuel. Les pages couvrant initial_capacity slots sont pré-faultées via
madvise(MADV_POPULATE_WRITE). Les pages au-delà sont committées à la demande.
§Panics
- Si
initial_capacity > virtual_capacity - Si
virtual_capacity * size_of::<T>()dépasseusize::MAX
§Errors
Retourne une erreur si mmap échoue (OOM système).
Source§impl<T> HiSlab<T>
impl<T> HiSlab<T>
Sourcepub fn insert(&mut self, val: T) -> u32
pub fn insert(&mut self, val: T) -> u32
Inserts a value and returns its index.
The returned index is stable and can be used to access the value until it is removed.
Sourcepub fn remove(&mut self, idx: u32) -> Option<T>
pub fn remove(&mut self, idx: u32) -> Option<T>
Removes the element at the given index and returns it, or None if the slot is empty.
The slot becomes available for future insertions.
Sourcepub fn is_occupied(&self, idx: u32) -> bool
pub fn is_occupied(&self, idx: u32) -> bool
Returns true if the slot at the given index is occupied.
Source§impl<T> HiSlab<T>
impl<T> HiSlab<T>
Sourcepub unsafe fn get_unchecked(&self, idx: u32) -> &T
pub unsafe fn get_unchecked(&self, idx: u32) -> &T
Returns a reference without checking if the slot is occupied.
§Safety
The caller must ensure the index is valid and occupied.
Sourcepub unsafe fn get_unchecked_mut(&mut self, idx: u32) -> &mut T
pub unsafe fn get_unchecked_mut(&mut self, idx: u32) -> &mut T
Returns a mutable reference without checking if the slot is occupied.
§Safety
The caller must ensure the index is valid and occupied.