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)>)infers vertex count and builds in O(n + m) time. - Fast adjacency access:
edges_from(u) → &[(to, weight, edge_id)] - Original‐edge lookup:
original_edge(edge_id) → Option<&(u, v, weight)> - Zero-panic on empty graphs (handles 0-edge input gracefully).
- Minimal private internals (
v,e) and a publicidarray of original edges.
Installation
Add to your Cargo.toml:
[]
= "0.4"
Or run:
Quick Start
use GraphRep;
API
struct GraphRep<K>
Constructors
-
pub fn from_list(edges: Vec<(usize, usize, K)>) -> SelfBuild a CSR graph from an edge-list.- Infers
n = max(u,v) + 1 - Handles
edges.is_empty()→ zero-vertex graph - Stores each undirected edge as two half-edges internally
- Records your original
(u,v,weight)tuples inid
- Infers
Accessors
-
pub fn num_vertices(&self) -> usizeReturns the number of verticesn. -
pub fn num_edges(&self) -> usizeReturns the number of undirected edgesm. -
pub fn edges_from(&self, u: usize) -> &[(usize, K, usize)]Returns a slice of half-edges out ofu: each tuple is(to: usize, weight: K, edge_id: usize). -
pub fn original_edge(&self, edge_id: usize) -> Option<&(usize, usize, K)>Look up your original(u, v, weight)byedge_id.
License
This project is licensed under the MIT License. See LICENSE for details.