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) - Fast adjacency access:
edges_from → &
* **Original-edge lookup**:
```rust
original_edge(edge_id) → Option<&(u, v, weight)>
-
In-place contraction by connected-component IDs:
contract_cc -
Zero-panic on empty graphs
-
Minimal private internals (
v,e) and a publicidarray of original edges
Installation
Add this to your Cargo.toml:
[]
= "0.4.1"
Or run:
Quick Start
use GraphRep;
API
struct GraphRep<K>
Constructors
pub fn from_list(edges: Vec<(usize, usize, K)>) -> SelfBuilds a CSR graph in O(n + m), inferringn = max(u,v)+1, handling empty input, storing each undirected edge twice, and recording your original(u,v,weight)tuples inid.
Accessors
pub fn num_vertices(&self) -> usize— number of verticesn.pub fn num_edges(&self) -> usize— number of undirected edgesm.pub fn edges_from(&self, u: usize) -> &[(usize, K, usize)]— adjacency list foru.pub fn original_edge(&self, edge_id: usize) -> Option<&(usize, usize, K)>— lookup original edge.
Mutators
-
pub fn contract_cc(&mut self, cc_ids: &[isize])In‐place contract this graph by assigning each vertexuthe super‐node IDcc_ids[u].- Rebuilds only
vande(the CSR fields), dropping self‐loops and carrying all originaledge_ids through. - Leaves
iduntouched, so you can always trace back to your original edges.
- Rebuilds only
License
This project is licensed under the MIT License.