pub struct CsrMatrix<I, D>where
I: Idx,{ /* private fields */ }Expand description
Compressed Sparse Row matrix mapping row indices to variable-length data.
For row i, its data is at data[indptr[i]..indptr[i+1]].
§Type Parameters
I: The row index type, must implementIdx.D: The data type stored in each row.
§Example
use miden_utils_indexing::{CsrMatrix, newtype_id};
newtype_id!(NodeId);
let mut csr = CsrMatrix::<NodeId, u32>::new();
csr.push_row([1, 2, 3]); // Row 0: [1, 2, 3]
csr.push_empty_row(); // Row 1: []
csr.push_row([4, 5]); // Row 2: [4, 5]
assert_eq!(csr.row(NodeId::from(0)), Some(&[1, 2, 3][..]));
assert_eq!(csr.row(NodeId::from(1)), Some(&[][..]));
assert_eq!(csr.row(NodeId::from(2)), Some(&[4, 5][..]));Implementations§
Source§impl<I, D> CsrMatrix<I, D>where
I: Idx,
impl<I, D> CsrMatrix<I, D>where
I: Idx,
Sourcepub fn with_capacity(num_rows: usize, num_elements: usize) -> CsrMatrix<I, D>
pub fn with_capacity(num_rows: usize, num_elements: usize) -> CsrMatrix<I, D>
Sourcepub fn push_row(
&mut self,
values: impl IntoIterator<Item = D>,
) -> Result<I, IndexedVecError>
pub fn push_row( &mut self, values: impl IntoIterator<Item = D>, ) -> Result<I, IndexedVecError>
Appends a new row with the given data values and returns the index of the newly added row.
Rows must be added in sequential order starting from row 0.
§Errors
Returns an error if the number of rows would exceed u32::MAX.
Sourcepub fn push_empty_row(&mut self) -> Result<I, IndexedVecError>
pub fn push_empty_row(&mut self) -> Result<I, IndexedVecError>
Appends an empty row (no data for this row index).
§Errors
Returns an error if the number of rows would exceed u32::MAX.
Sourcepub fn fill_to_row(&mut self, target_row: I) -> Result<(), IndexedVecError>
pub fn fill_to_row(&mut self, target_row: I) -> Result<(), IndexedVecError>
Appends empty rows to fill gaps up to (but not including) target_row.
If target_row is less than or equal to the current number of rows, this is a no-op.
§Errors
Returns an error if the number of rows would exceed u32::MAX.
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Returns the total number of data elements across all rows.
Sourcepub fn row(&self, row: I) -> Option<&[D]>
pub fn row(&self, row: I) -> Option<&[D]>
Returns the data slice for the given row, or None if the row doesn’t exist.
Sourcepub fn row_expect(&self, row: I) -> &[D]
pub fn row_expect(&self, row: I) -> &[D]
Returns the data slice for the given row, panicking if the row doesn’t exist.
§Panics
Panics if row is out of bounds.
Sourcepub fn iter(&self) -> impl Iterator<Item = (I, &[D])>
pub fn iter(&self) -> impl Iterator<Item = (I, &[D])>
Returns an iterator over all (row_index, data_slice) pairs.
Sourcepub fn iter_enumerated(&self) -> impl Iterator<Item = (I, usize, &D)>
pub fn iter_enumerated(&self) -> impl Iterator<Item = (I, usize, &D)>
Returns an iterator over all data elements with their (row_index, position_in_row, &data).
Sourcepub fn validate(&self) -> Result<(), CsrValidationError>
pub fn validate(&self) -> Result<(), CsrValidationError>
Validates the CSR structural invariants.
Checks:
indptrstarts at 0 (if non-empty)indptris monotonically increasingindptrends atdata.len()
For domain-specific validation of data values, use validate_with.
Sourcepub fn validate_with<F>(&self, f: F) -> Result<(), CsrValidationError>
pub fn validate_with<F>(&self, f: F) -> Result<(), CsrValidationError>
Validates structural invariants plus domain-specific data constraints.
The callback is invoked for each data element. Return false to indicate
an invalid value.
§Arguments
f: A function that returnstrueif the data value is valid.
Trait Implementations§
Source§impl<I, D> Deserializable for CsrMatrix<I, D>where
I: Idx,
D: Deserializable,
impl<I, D> Deserializable for CsrMatrix<I, D>where
I: Idx,
D: Deserializable,
Source§fn min_serialized_size() -> usize
fn min_serialized_size() -> usize
Returns the minimum serialized size for a CsrMatrix.
A CsrMatrix serializes as:
- data_len (vint, minimum 1 byte)
- data elements (minimum 0 if empty)
- indptr_len (vint, minimum 1 byte)
- indptr elements (minimum 0 if empty)
Total minimum: 2 bytes (two vint length prefixes for empty matrix)
Source§fn read_from<R>(source: &mut R) -> Result<CsrMatrix<I, D>, DeserializationError>where
R: ByteReader,
fn read_from<R>(source: &mut R) -> Result<CsrMatrix<I, D>, DeserializationError>where
R: ByteReader,
source, attempts to deserialize these bytes
into Self, and returns the result. Read moreSource§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§fn read_from_bytes_with_budget(
bytes: &[u8],
budget: usize,
) -> Result<Self, DeserializationError>
fn read_from_bytes_with_budget( bytes: &[u8], budget: usize, ) -> Result<Self, DeserializationError>
Self from bytes with a byte budget limit. Read moreSource§impl<'de, I, D> Deserialize<'de> for CsrMatrix<I, D>
impl<'de, I, D> Deserialize<'de> for CsrMatrix<I, D>
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CsrMatrix<I, D>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CsrMatrix<I, D>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<I, D> Serializable for CsrMatrix<I, D>where
I: Idx,
D: Serializable,
impl<I, D> Serializable for CsrMatrix<I, D>where
I: Idx,
D: Serializable,
Source§fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
fn write_into<W>(&self, target: &mut W)where
W: ByteWriter,
self into bytes and writes these bytes into the target.Source§fn get_size_hint(&self) -> usize
fn get_size_hint(&self) -> usize
Source§impl<I, D> Serialize for CsrMatrix<I, D>
impl<I, D> Serialize for CsrMatrix<I, D>
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<I, D> Eq for CsrMatrix<I, D>
impl<I, D> StructuralPartialEq for CsrMatrix<I, D>where
I: Idx,
Auto Trait Implementations§
impl<I, D> Freeze for CsrMatrix<I, D>
impl<I, D> RefUnwindSafe for CsrMatrix<I, D>where
I: RefUnwindSafe,
D: RefUnwindSafe,
impl<I, D> Send for CsrMatrix<I, D>
impl<I, D> Sync for CsrMatrix<I, D>
impl<I, D> Unpin for CsrMatrix<I, D>
impl<I, D> UnwindSafe for CsrMatrix<I, D>where
I: UnwindSafe,
D: 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more