pub struct SparseSet<T, Idx, S, const TRACK: bool = true>{ /* private fields */ }Expand description
Semi-persistent sparse set with stable IDs.
Implementations§
Source§impl<T, Idx, S, const TRACK: bool> SparseSet<T, Idx, S, TRACK>
impl<T, Idx, S, const TRACK: bool> SparseSet<T, Idx, S, TRACK>
pub fn len(&self) -> Idx
pub fn is_empty(&self) -> bool
Sourcepub fn set(&mut self, id: Idx, value: T)
pub fn set(&mut self, id: Idx, value: T)
Overwrite a live id’s value in place (position and id unchanged).
Sourcepub fn remove(&mut self, id: Idx)
pub fn remove(&mut self, id: Idx)
Remove a live id. Swap-removes its dense slot with the last element and
parks the freed id at the new boundary indices[n-1] (the first free
slot), preserving the permutation by a transposition.
Sourcepub fn remove_value(&mut self, val: &T) -> boolwhere
T: PartialEq,
pub fn remove_value(&mut self, val: &T) -> boolwhere
T: PartialEq,
Remove the first live entry whose VALUE equals val (production
remove_value parity: linear scan of the dense region, then the
verified remove on the id found at that position).
Sourcepub fn data(&self) -> &Vec<T, Idx, S, TRACK>
pub fn data(&self) -> &Vec<T, Idx, S, TRACK>
Read-only access to the dense value vector (production data()
parity: exposes the packed live values for iteration).
Sourcepub fn try_add(&mut self, value: T) -> Result<Idx, ContainerError>
pub fn try_add(&mut self, value: T) -> Result<Idx, ContainerError>
Total add.
Sourcepub fn try_get(&self, id: Idx) -> Result<T, ContainerError>
pub fn try_get(&self, id: Idx) -> Result<T, ContainerError>
Total get: Err(IndexOutOfBounds) for an id that is not live.
Sourcepub fn try_mark(
&mut self,
shrink: ShrinkPolicy,
) -> Result<SparseSetToken, ContainerError>
pub fn try_mark( &mut self, shrink: ShrinkPolicy, ) -> Result<SparseSetToken, ContainerError>
Total mark: TRACK first, then the six column headrooms as one answer.
Sourcepub fn is_valid_token(&self, token: &SparseSetToken) -> bool
pub fn is_valid_token(&self, token: &SparseSetToken) -> bool
Whether the composite token is restorable now. Every constituent must be restorable, which is the validation half of aggregate atomicity.
pub fn restore(&mut self, token: SparseSetToken)
Source§impl<T, Idx, const TRACK: bool> SparseSet<T, Idx, ParallelStore<T, Idx>, TRACK>
impl<T, Idx, const TRACK: bool> SparseSet<T, Idx, ParallelStore<T, Idx>, TRACK>
Sourcepub fn new() -> SparseSet<T, Idx, ParallelStore<T, Idx>, TRACK>
pub fn new() -> SparseSet<T, Idx, ParallelStore<T, Idx>, TRACK>
Empty sparse set over a ParallelStore (any T: Copy; production
SparseSet::new parity).
Source§impl<T, Idx, const TRACK: bool> SparseSet<T, Idx, InlineStore<T, Idx>, TRACK>
impl<T, Idx, const TRACK: bool> SparseSet<T, Idx, InlineStore<T, Idx>, TRACK>
Sourcepub fn new_inline() -> SparseSet<T, Idx, InlineStore<T, Idx>, TRACK>
pub fn new_inline() -> SparseSet<T, Idx, InlineStore<T, Idx>, TRACK>
Empty sparse set over an InlineStore (T: Tagged; production
SparseSet::new_inline parity).