Struct libreda_db::slab_alloc::SlabAlloc
source · [−]pub struct SlabAlloc<T, IndexType = u32, IdType = u32> {
data: Vec<Element<IdType, T>>,
free_indices: Vec<IndexType>,
len: usize,
}
Expand description
Container which efficiently allocates space for its elements.
Fields
data: Vec<Element<IdType, T>>
free_indices: Vec<IndexType>
len: usize
Number of elements currently in the map.
Implementations
sourceimpl<T, IndexType, IdType> SlabAlloc<T, IndexType, IdType> where
IndexType: PrimInt + Unsigned + ToPrimitive + FromPrimitive,
IdType: PrimInt + Unsigned,
impl<T, IndexType, IdType> SlabAlloc<T, IndexType, IdType> where
IndexType: PrimInt + Unsigned + ToPrimitive + FromPrimitive,
IdType: PrimInt + Unsigned,
sourcepub fn get_mut(&mut self, index: SlabIndex<IndexType, IdType>) -> Option<&mut T>
pub fn get_mut(&mut self, index: SlabIndex<IndexType, IdType>) -> Option<&mut T>
Access an element.
pub fn contains_key(&self, index: SlabIndex<IndexType, IdType>) -> bool
sourcepub fn insert(&mut self, value: T) -> SlabIndex<IndexType, IdType>
pub fn insert(&mut self, value: T) -> SlabIndex<IndexType, IdType>
Insert an element and return the index of it.
Panics
Panics when the amount of indices is exhausted. This happens
when there are already IndexType::max_value()
elements in the container.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
sourcepub fn iter(&self) -> impl Iterator<Item = (SlabIndex<IndexType, IdType>, &T)>
pub fn iter(&self) -> impl Iterator<Item = (SlabIndex<IndexType, IdType>, &T)>
Iterate over all key-value pairs.
sourcepub fn iter_mut(
&mut self
) -> impl Iterator<Item = (SlabIndex<IndexType, IdType>, &mut T)>
pub fn iter_mut(
&mut self
) -> impl Iterator<Item = (SlabIndex<IndexType, IdType>, &mut T)>
Iterate over all key-value pairs.
sourcepub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn values_mut(&mut self) -> impl Iterator<Item = &mut T>
Iterate over all mutable values in the map.
Trait Implementations
sourceimpl<T: Default, IndexType: Default, IdType: Default> Default for SlabAlloc<T, IndexType, IdType>
impl<T: Default, IndexType: Default, IdType: Default> Default for SlabAlloc<T, IndexType, IdType>
sourceimpl<'de, T, IndexType, IdType> Deserialize<'de> for SlabAlloc<T, IndexType, IdType> where
T: Deserialize<'de>,
IndexType: Deserialize<'de>,
IdType: Deserialize<'de>,
impl<'de, T, IndexType, IdType> Deserialize<'de> for SlabAlloc<T, IndexType, IdType> where
T: Deserialize<'de>,
IndexType: Deserialize<'de>,
IdType: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl<T, IndexType, IdType> RefUnwindSafe for SlabAlloc<T, IndexType, IdType> where
IdType: RefUnwindSafe,
IndexType: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, IndexType, IdType> Send for SlabAlloc<T, IndexType, IdType> where
IdType: Send,
IndexType: Send,
T: Send,
impl<T, IndexType, IdType> Sync for SlabAlloc<T, IndexType, IdType> where
IdType: Sync,
IndexType: Sync,
T: Sync,
impl<T, IndexType, IdType> Unpin for SlabAlloc<T, IndexType, IdType> where
IdType: Unpin,
IndexType: Unpin,
T: Unpin,
impl<T, IndexType, IdType> UnwindSafe for SlabAlloc<T, IndexType, IdType> where
IdType: UnwindSafe,
IndexType: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more