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>
impl<T> KhrSegmentedVec<T>
sourcefn idx_to_segmented(&self, idx: u16) -> Option<(Range<usize>, usize)>
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]
.
sourcefn insert_in_order(
&mut self,
idx: u16,
value: T,
merge_duplicates: impl Fn(T, T) -> T
)
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.
sourcepub fn from_in_order_iter(
it: impl IntoIterator<Item = (u16, T)>,
merge_duplicates: impl Fn(T, T) -> T
) -> Self
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.