pub struct CsrMatrix {
pub num_rows: usize,
pub num_cols: usize,
pub row_ptr: Vec<u64>,
pub col_idx: Vec<u32>,
pub values: Option<Vec<f64>>,
}Expand description
Compressed Sparse Row matrix for graph adjacency.
For a graph with N nodes and M edges:
row_ptr: N+1 elements, where row_ptr[i] is the start of row i’s edgescol_idx: M elements, the column indices (neighbor node IDs)values: Optional M elements for weighted graphs
Fields§
§num_rows: usizeNumber of rows (nodes).
num_cols: usizeNumber of columns (typically equals num_rows for square adjacency).
row_ptr: Vec<u64>Row pointers (length = num_rows + 1).
col_idx: Vec<u32>Column indices (length = nnz).
values: Option<Vec<f64>>Optional edge values/weights.
Implementations§
Source§impl CsrMatrix
impl CsrMatrix
Sourcepub fn from_edges(num_nodes: usize, edges: &[(u32, u32)]) -> Self
pub fn from_edges(num_nodes: usize, edges: &[(u32, u32)]) -> Self
Sourcepub fn from_weighted_edges(num_nodes: usize, edges: &[(u32, u32, f64)]) -> Self
pub fn from_weighted_edges(num_nodes: usize, edges: &[(u32, u32, f64)]) -> Self
Create CSR from edge list with weights.
Sourcepub fn num_nonzeros(&self) -> usize
pub fn num_nonzeros(&self) -> usize
Number of non-zero entries (edges).
Sourcepub fn degree(&self, node: NodeId) -> usize
pub fn degree(&self, node: NodeId) -> usize
Get the degree (number of outgoing edges) of a node.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CsrMatrix
impl RefUnwindSafe for CsrMatrix
impl Send for CsrMatrix
impl Sync for CsrMatrix
impl Unpin for CsrMatrix
impl UnwindSafe for CsrMatrix
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
Mutably borrows from an owned value. Read more