pub struct KhrSegmentedVec<T> {
    flattened: Vec<Option<T>>,
    block_starts: SmallVec<[u16; 8]>,
}
Expand description

Khronos-oriented segmented sparse array (see KhrSegmented).

Fields§

§flattened: Vec<Option<T>>

Concatenation of values for indices lower than 4096, with values for indices in a 64-sized/aligned block starting at/above 4096.

Gaps are present (as None), but only if there are more values at some point after the gap, in the 0..=4096 index range, or in the same 64-sized/aligned block (i.e. tailing gaps are elided).

§block_starts: SmallVec<[u16; 8]>

Starting indices in flattened for every 64-sized/aligned block.

For example, if an index i >= 4096 is present, its value can be found at flattened[block_starts[(i - 4096) / 64] + (i % 64)].

Implementations§

source§

impl<T> KhrSegmentedVec<T>

source

fn idx_to_segmented(&self, idx: u16) -> Option<(Range<usize>, usize)>

If idx is not in an out-of-range block, returns the pair of a “segment range” and an “intra-segment index”.

For example, if an index i is present, then idx_to_segmented(i) will return Some((seg_range, intra_seg_idx)), and the value can be found at flattened[seg_range][intra_seg_idx].

source

fn insert_in_order( &mut self, idx: u16, value: T, merge_duplicates: impl Fn(T, T) -> T )

Add a new value, with an index greater than all previous indices.

An exception is made for duplicates, which have to be handled by the merge_duplicates closure, instead of being outright disallowed.

source

pub fn from_in_order_iter( it: impl IntoIterator<Item = (u16, T)>, merge_duplicates: impl Fn(T, T) -> T ) -> Self

Construct a KhrSegmentedVec out of an iterator with ordered indices.

An exception is made for duplicates, which have to be handled by the merge_duplicates closure, instead of being outright disallowed.

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T> Unpin for KhrSegmentedVec<T>
where T: Unpin,

§

impl<T> UnwindSafe for KhrSegmentedVec<T>
where T: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.