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.
- Unit tested and ready for algorithmic use cases.
Installation
Add graphix to your Cargo.toml dependencies:
[]
= "0.1"
Or with cargo:
Quick Start
use GraphRep;
API
GraphRep<K>
-
GraphRep::new(n: usize, m: usize) -> SelfCreate a graph withnvertices and space formundirected edges. -
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. -
finish_v(&mut self)Finalize the internal adjacency list structure. Must be called before usingedges_from. -
edges_from(&self, vertex: usize) -> Vec<(usize, K)>Get a list of neighbor–weight pairs for a given vertex. -
num_vertices(&self) -> usizeReturn the number of vertices. -
num_edges(&self) -> usizeReturn the number of undirected edges.
License
This project is licensed under the MIT License. See the LICENSE file for details.