pub struct Compact2dArray<T> { /* private fields */ }Expand description
A 2D array stored in Compressed Sparse Row (CSR) format: every row may have a different length, and all rows live contiguously in one backing buffer.
Two parallel vectors back it:
data— all row elements, concatenated;indptr— the start offset of each row indata; its last element equalsdata.len(), so rowioccupiesdata[indptr[i]..indptr[i + 1]].
Rows are immutable once inserted (you can still mutate their elements in place via
Compact2dArray::row_mut). Provides
Row views, this returns borrowed slices — the borrow checker enforces the
“inserting a row invalidates outstanding rows” invariant for free.
Implementations§
Source§impl<T> Compact2dArray<T>
impl<T> Compact2dArray<T>
Sourcepub fn from_data_and_indptr(
data: Vec<T>,
indptr: Vec<i32>,
) -> Result<Self, Compact2dArrayError>
pub fn from_data_and_indptr( data: Vec<T>, indptr: Vec<i32>, ) -> Result<Self, Compact2dArrayError>
Builds an array directly from a CSR representation, validating the invariants.
§Errors
Returns Compact2dArrayError if indptr is empty, does not start with 0, is
not non-decreasing, or does not end at data.len().
Sourcepub fn get(&self, i: usize) -> Option<&[T]>
pub fn get(&self, i: usize) -> Option<&[T]>
Returns row i as a slice, or None if out of bounds.
Sourcepub fn row_range(&self, i: usize) -> Range<usize> ⓘ
pub fn row_range(&self, i: usize) -> Range<usize> ⓘ
The positions of row i within Self::data. They stay valid while rows are appended,
so a row can be walked by index while the array grows.
§Panics
Panics if i is out of bounds.
Source§impl<T: Clone> Compact2dArray<T>
impl<T: Clone> Compact2dArray<T>
Sourcepub fn from_row_sizes(row_sizes: &[i32]) -> Selfwhere
T: Default,
pub fn from_row_sizes(row_sizes: &[i32]) -> Selfwhere
T: Default,
Builds an array from per-row sizes, with every element default-constructed.
Sourcepub fn reset_with_row_sizes(&mut self, row_sizes: &[i32])where
T: Default,
pub fn reset_with_row_sizes(&mut self, row_sizes: &[i32])where
T: Default,
Resets the array to row_sizes.len() rows of default-constructed elements.
§Panics
Panics if any row size is negative, or if the total size exceeds the i32 limit.
Sourcepub fn push_row(&mut self, new_data: &[T]) -> usize
pub fn push_row(&mut self, new_data: &[T]) -> usize
Appends a new row, returning its index.
§Panics
Panics if the total size would exceed the i32 limit.
Sourcepub fn push_row_noncontiguous(&mut self, first: T, rest: &[T]) -> usize
pub fn push_row_noncontiguous(&mut self, first: T, rest: &[T]) -> usize
Appends a new row consisting of one leading element followed by rest.
Mirrors the C++ PushBackNonContiguous, used by the grammar-expression encoding.
§Panics
Panics if the total size would exceed the i32 limit.
Source§impl<T> Compact2dArray<T>
impl<T> Compact2dArray<T>
Sourcepub fn push_in_latest_row(&mut self, new_data: T)
pub fn push_in_latest_row(&mut self, new_data: T)
Appends one element to the most recently inserted row.
§Panics
Panics if the array has no rows yet, or if the total size would exceed the i32 limit.
Source§impl Compact2dArray<i32>
impl Compact2dArray<i32>
Sourcepub fn serialize_json_value(&self) -> Value
pub fn serialize_json_value(&self) -> Value
Serializes in the C++ reflection form {"data_":[...],"indptr_":[...]}.
Trait Implementations§
Source§impl<T: Clone> Clone for Compact2dArray<T>
impl<T: Clone> Clone for Compact2dArray<T>
Source§impl<T: Debug> Debug for Compact2dArray<T>
impl<T: Debug> Debug for Compact2dArray<T>
Source§impl<T> Default for Compact2dArray<T>
impl<T> Default for Compact2dArray<T>
Source§impl<'de, T> Deserialize<'de> for Compact2dArray<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Compact2dArray<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<T: Eq> Eq for Compact2dArray<T>
Source§impl<T: Hash> Hash for Compact2dArray<T>
impl<T: Hash> Hash for Compact2dArray<T>
Source§impl<T: PartialEq> PartialEq for Compact2dArray<T>
impl<T: PartialEq> PartialEq for Compact2dArray<T>
Source§impl<T> Serialize for Compact2dArray<T>where
T: Serialize,
impl<T> Serialize for Compact2dArray<T>where
T: Serialize,
impl<T: PartialEq> StructuralPartialEq for Compact2dArray<T>
Auto Trait Implementations§
impl<T> Freeze for Compact2dArray<T>
impl<T> RefUnwindSafe for Compact2dArray<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for Compact2dArray<T>
impl<T> Sync for Compact2dArray<T>
impl<T> Unpin for Compact2dArray<T>
impl<T> UnsafeUnpin for Compact2dArray<T>where
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for Compact2dArray<T>where
Vec<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more