Skip to main content

HiSlab

Struct HiSlab 

Source
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>

Source

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épasse usize::MAX
§Errors

Retourne une erreur si mmap échoue (OOM système).

Source§

impl<T> HiSlab<T>

Source

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.

Source

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.

Source

pub fn is_occupied(&self, idx: u32) -> bool

Returns true if the slot at the given index is occupied.

Source

pub fn get(&self, idx: u32) -> Option<&T>

Returns a reference to the element at the given index, or None if empty.

Source

pub fn get_mut(&mut self, idx: u32) -> Option<&mut T>

Returns a mutable reference to the element at the given index, or None if empty.

Source§

impl<T> HiSlab<T>

Source

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.

Source

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.

Source§

impl<T> HiSlab<T>

Source

pub fn for_each_occupied<F>(&self, f: F)
where F: FnMut(u32, &T),

Iterates over all occupied slots with maximum performance.

This is faster than using the iterator for simple operations as it avoids iterator overhead.

Trait Implementations§

Source§

impl<T> Drop for HiSlab<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> Index<u32> for HiSlab<T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: u32) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<T> IndexMut<u32> for HiSlab<T>

Source§

fn index_mut(&mut self, idx: u32) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'a, T> IntoIterator for &'a HiSlab<T>

Source§

type Item = (u32, &'a T)

The type of the elements being iterated over.
Source§

type IntoIter = SlabIter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut HiSlab<T>

Source§

type Item = (u32, &'a mut T)

The type of the elements being iterated over.
Source§

type IntoIter = SlabIterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for HiSlab<T>

Source§

type Item = (u32, T)

The type of the elements being iterated over.
Source§

type IntoIter = SlabIntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for HiSlab<T>

§

impl<T> RefUnwindSafe for HiSlab<T>
where T: RefUnwindSafe,

§

impl<T> !Send for HiSlab<T>

§

impl<T> !Sync for HiSlab<T>

§

impl<T> Unpin for HiSlab<T>

§

impl<T> UnsafeUnpin for HiSlab<T>

§

impl<T> UnwindSafe for HiSlab<T>
where T: RefUnwindSafe,

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.