pub struct SparseSequence<T> { /* private fields */ }Expand description
Mutable sparse indexed storage with stable holes and bounded allocation.
Logical length is stored separately from values. Writing a distant index
allocates only its fixed-size chunk; intervening indices remain holes.
max_len is an explicit work limit applied to every operation that can grow
the logical sequence.
Implementations§
Source§impl<T> SparseSequence<T>
impl<T> SparseSequence<T>
Sourcepub fn new(max_len: usize) -> Self
pub fn new(max_len: usize) -> Self
Construct an empty store whose logical length may not exceed max_len.
Sourcepub fn occupied_len(&self) -> usize
pub fn occupied_len(&self) -> usize
Return the number of occupied positions.
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Return the mutation revision.
It advances for every successful operation that changes length or an occupied position, using wrapping arithmetic so mutation never fails merely because the diagnostic counter reached its integer limit.
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Return the value at index, or None for a hole or out-of-range index.
Sourcepub fn contains_index(&self, index: usize) -> bool
pub fn contains_index(&self, index: usize) -> bool
Return whether index is an occupied in-range position.
Sourcepub fn set(
&mut self,
index: usize,
value: T,
) -> Result<Option<T>, SparseSequenceError>
pub fn set( &mut self, index: usize, value: T, ) -> Result<Option<T>, SparseSequenceError>
Set index, growing the logical length with holes when necessary.
Returns the previously stored value, if the position was occupied.
Sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Remove and return the value at index, leaving a stable hole.
Sourcepub fn set_len(&mut self, new_len: usize) -> Result<(), SparseSequenceError>
pub fn set_len(&mut self, new_len: usize) -> Result<(), SparseSequenceError>
Set the logical length, creating holes on growth and dropping values on truncation.
Sourcepub fn occupied_in<R>(&self, range: R) -> impl Iterator<Item = (usize, &T)>where
R: RangeBounds<usize>,
pub fn occupied_in<R>(&self, range: R) -> impl Iterator<Item = (usize, &T)>where
R: RangeBounds<usize>,
Traverse occupied (index, value) pairs within a bounded index range.
The range is intersected with the logical sequence, and holes do not produce iterator items or work proportional to the logical length.
Trait Implementations§
Source§impl<T: Clone> Clone for SparseSequence<T>
impl<T: Clone> Clone for SparseSequence<T>
Source§fn clone(&self) -> SparseSequence<T>
fn clone(&self) -> SparseSequence<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more