graphix
A lightweight Rust library providing a compact CSR (Compressed Sparse Row) representation of undirected graphs, with full tracking of original edge IDs. Optimized for sparse graphs and supports weighted edges of any Copy type.
Features
-
One-shot CSR construction via
GraphRep::from_list(Vec<(u, v, weight)>)in O(n + m) -
Efficient adjacency access:
edges_from → & -
Original-edge lookup:
original_edge → -
Dynamic CSR update with existing edge IDs:
update_v_e -
Retrieve edge sets:
all_edges()returns all original edges with IDscurrent_edges()gives the current deduplicated edge list
-
Zero-panic on empty graphs
-
Public
idarray for traceability
Installation
Add this to your Cargo.toml:
[]
= "0.4.1"
Or use:
Quick Start
use GraphRep;
API
struct GraphRep<K>
Constructors
from_list(edges: Vec<(usize, usize, K)>) -> SelfBuilds a graph in O(n + m), infersn = max(u,v)+1, and stores all undirected edges with stable IDs.
Accessors
num_vertices(&self) -> usizenum_edges(&self) -> usizeedges_from(&self, u: usize) -> &[(usize, K, usize)]original_edge(&self, edge_id: usize) -> Option<&(usize, usize, K)>all_edges(&self) -> Vec<(usize, usize, K, usize)>current_edges(&self) -> Vec<(usize, usize, K, usize)>
Mutators
update_v_e(&mut self, &[(usize, usize, K, usize)])Rebuilds CSR structure from a fresh list of edges, retaining original edge IDs.
License
This project is licensed under the MIT License.