Skip to main content

SparseSequence

Struct SparseSequence 

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

Source

pub fn new(max_len: usize) -> Self

Construct an empty store whose logical length may not exceed max_len.

Source

pub fn len(&self) -> usize

Return the logical length, including holes.

Source

pub fn is_empty(&self) -> bool

Return whether the logical sequence is empty.

Source

pub fn max_len(&self) -> usize

Return the configured logical-length limit.

Source

pub fn occupied_len(&self) -> usize

Return the number of occupied positions.

Source

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.

Source

pub fn get(&self, index: usize) -> Option<&T>

Return the value at index, or None for a hole or out-of-range index.

Source

pub fn contains_index(&self, index: usize) -> bool

Return whether index is an occupied in-range position.

Source

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.

Source

pub fn remove(&mut self, index: usize) -> Option<T>

Remove and return the value at index, leaving a stable hole.

Source

pub fn set_len(&mut self, new_len: usize) -> Result<(), SparseSequenceError>

Set the logical length, creating holes on growth and dropping values on truncation.

Source

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>

Source§

fn clone(&self) -> SparseSequence<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for SparseSequence<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Eq> Eq for SparseSequence<T>

Source§

impl<T: PartialEq> PartialEq for SparseSequence<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SparseSequence<T>

§

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

§

impl<T> Send for SparseSequence<T>
where T: Send,

§

impl<T> Sync for SparseSequence<T>
where T: Sync,

§

impl<T> Unpin for SparseSequence<T>

§

impl<T> UnsafeUnpin for SparseSequence<T>

§

impl<T> UnwindSafe for SparseSequence<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.