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: usizeNumber of elements currently in the map.
Implementations§
source§impl<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§
source§impl<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>
source§impl<'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>,
source§fn 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