graphix
A lightweight Rust library providing a compact and efficient representation of undirected graphs using a compressed adjacency list format. Optimized for sparse graphs and supports weighted edges with customizable types.
Features
- GraphRep: a compressed adjacency list representation for undirected graphs.
- Efficient memory layout using flat vectors.
- Supports edge weights of any
Copy + Ordtype. - Fast adjacency list access.
- Construct directly from an edge list with
GraphRep::from_list, inferring the number of vertices automatically. - Unit tested and ready for algorithmic use cases.
Installation
Add graphix to your Cargo.toml dependencies:
[]
= "0.1"
Or with cargo:
Quick Start
Manual construction
use GraphRep;
From an edge list
use GraphRep;
API
GraphRep<K>
-
GraphRep::new(n: usize, m: usize) -> SelfCreate a graph withnvertices and space formundirected edges. -
GraphRep::add_edge(&mut self, u: usize, v: usize, weight: K)Add an undirected edge betweenuandvwith a given weight. Internally stores each undirected edge as two directed entries. -
GraphRep::finish_v(&mut self)Finalize the internal adjacency list structure. Must be called before usingedges_fromwhen built manually. -
GraphRep::edges_from(&self, vertex: usize) -> Vec<(usize, K)>Get a list of (neighbor, weight) pairs for a given vertex. -
GraphRep::num_vertices(&self) -> usizeReturn the number of vertices. -
GraphRep::num_edges(&self) -> usizeReturn the number of undirected edges. -
GraphRep::from_list(edges: Vec<(usize, usize, K)>) -> SelfBuild a graph directly from an edge list. Infers the number of vertices asmax(u, v) + 1, adds all edges, and finalizes the structure.
License
This project is licensed under the MIT License. See the LICENSE file for details.