Skip to main content

Compact2dArray

Struct Compact2dArray 

Source
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 in data; its last element equals data.len(), so row i occupies data[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>

Source

pub fn new() -> Self

Creates an empty array (zero rows).

Source

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().

Source

pub fn len(&self) -> usize

Number of rows.

Source

pub fn is_empty(&self) -> bool

Whether there are zero rows.

Source

pub fn data_len(&self) -> usize

Total number of elements across all rows.

Source

pub fn get(&self, i: usize) -> Option<&[T]>

Returns row i as a slice, or None if out of bounds.

Source

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

pub fn row(&self, i: usize) -> &[T]

Returns row i as a slice.

§Panics

Panics if i is out of bounds (an internal invariant violation).

Source

pub fn row_mut(&mut self, i: usize) -> &mut [T]

Returns row i as a mutable slice.

§Panics

Panics if i is out of bounds.

Source

pub fn back(&self) -> &[T]

Returns the last row.

§Panics

Panics if there are no rows.

Source

pub fn iter(&self) -> impl Iterator<Item = &[T]>

Iterates over the rows as slices.

Source

pub fn data(&self) -> &[T]

The flat backing data buffer.

Source

pub fn indptr(&self) -> &[i32]

The row-offset (index pointer) buffer.

Source

pub fn pop_back(&mut self, cnt: usize)

Removes the last cnt rows.

§Panics

Panics if cnt exceeds the number of rows.

Source§

impl<T: Clone> Compact2dArray<T>

Source

pub fn from_row_sizes(row_sizes: &[i32]) -> Self
where T: Default,

Builds an array from per-row sizes, with every element default-constructed.

Source

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.

Source

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.

Source

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>

Source

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>

Source

pub fn serialize_json_value(&self) -> Value

Serializes in the C++ reflection form {"data_":[...],"indptr_":[...]}.

Source

pub fn deserialize_json_value(value: &Value) -> Result<Self, String>

Deserializes the C++ reflection form.

§Errors

Returns an error string when the JSON shape is invalid.

Trait Implementations§

Source§

impl<T: Clone> Clone for Compact2dArray<T>

Source§

fn clone(&self) -> Self

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 Compact2dArray<T>

Source§

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

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

impl<T> Default for Compact2dArray<T>

Source§

fn default() -> Self

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

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Eq> Eq for Compact2dArray<T>

Source§

impl<T: Hash> Hash for Compact2dArray<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for Compact2dArray<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
Source§

impl<T> Serialize for Compact2dArray<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Compact2dArray<T>

Auto Trait Implementations§

§

impl<T> Freeze for Compact2dArray<T>
where Vec<T>: Freeze,

§

impl<T> RefUnwindSafe for Compact2dArray<T>
where Vec<T>: RefUnwindSafe,

§

impl<T> Send for Compact2dArray<T>
where Vec<T>: Send,

§

impl<T> Sync for Compact2dArray<T>
where Vec<T>: Sync,

§

impl<T> Unpin for Compact2dArray<T>
where Vec<T>: Unpin,

§

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.