Skip to main content

FlatVecVec

Struct FlatVecVec 

Source
pub struct FlatVecVec<T> { /* private fields */ }
Expand description

A flat, cache-friendly replacement for Vec<Vec<T>>.

During the build phase, items are pushed into per-node inner Vecs (same as before). After building is complete, flatten() compacts all inner Vecs into a single contiguous Vec<T> with a (start, len) offset table per node. All subsequent reads use the flat layout, eliminating N heap allocations and pointer chasing.

§Lifecycle

new(n) → push_to(idx, item)* → sort_each_and_flatten(key_fn) → get_slice(idx)*
         ── build phase ──       ── transition ──                ── read phase ──

Implementations§

Source§

impl<T> FlatVecVec<T>

Source

pub fn heap_bytes(&self, per_element_size: usize) -> usize

Approximate heap bytes retained. Sums capacity of the flattened data + offsets tables and the per-node build Vecs (in case sort_each_and_flatten hasn’t been called yet). per_element_size should be size_of::<T>().

Source

pub fn new(node_count: usize) -> Self

Create a new FlatVecVec with node_count empty slots (build phase).

Source

pub fn push_to(&mut self, node_index: usize, item: T)

Push an item to the inner Vec at node_index (build phase).

§Panics

Panics if already flattened or if node_index >= len().

Source

pub fn build_mut(&mut self, node_index: usize) -> &mut Vec<T>

Get a mutable reference to the inner Vec at node_index (build phase).

Source

pub fn build_iter_mut(&mut self) -> IterMut<'_, Vec<T>>

Iterate mutably over all inner Vecs (build phase, e.g. for clearing).

Source

pub fn build_get(&self, node_index: usize) -> Option<&Vec<T>>

Get a reference to the inner Vec at node_index during build phase. During read phase, returns None (use get_slice instead).

Source

pub fn len(&self) -> usize

Number of node slots.

Source

pub fn is_flattened(&self) -> bool

Returns true if this is in read (flattened) mode.

Source

pub fn get_slice(&self, node_index: usize) -> &[T]

Get a slice for the node at node_index (read phase). Returns empty slice if index is out of bounds or not yet flattened (falls back to build-phase data if not yet flattened).

Source

pub fn sort_each_and_flatten<K: Ord + Eq>(&mut self, key_fn: impl Fn(&T) -> K)

Flatten: sort each inner Vec by key, deduplicate by keeping the last occurrence of each key (CSS cascade: later source order wins among equal specificity), then compact into flat storage. Drains all build-phase Vecs. After this call, only get_slice() works.

Source

pub fn flatten(&mut self)

Flatten without sorting (for data that’s already sorted).

Source

pub fn retain(&mut self, predicate: impl Fn(&T) -> bool)
where T: Clone,

Rebuild flat storage, keeping only items matching predicate. Must be called after flatten. Preserves per-node ordering.

Source

pub fn retain_with_node_index(&mut self, predicate: impl Fn(usize, &T) -> bool)
where T: Clone,

Like retain, but passes each item’s owning node index to the predicate. Must be called after flatten. Preserves per-node ordering.

Source

pub fn extend_from(&mut self, other: &mut Self)

Extend this FlatVecVec with all nodes from other (append for DOM merge). Both must be in build phase, or both must be flattened.

Trait Implementations§

Source§

impl<T: Clone> Clone for FlatVecVec<T>

Source§

fn clone(&self) -> FlatVecVec<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 FlatVecVec<T>

Source§

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

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

impl<T> Default for FlatVecVec<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: PartialEq> PartialEq for FlatVecVec<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for FlatVecVec<T>

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for FlatVecVec<T>

§

impl<T> UnwindSafe for FlatVecVec<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> 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.