graaf 0.30.0

Functions and types for working with graphs
Documentation

Graaf!Build status Crates.io API reference Coverage Status

Graph algorithms, operations, generators, and representations.

See the changelog for a provisional roadmap.

  1. Installation
  2. Usage
  3. Features

Installation

Add the following to your Cargo.toml:

[dependencies]
graaf = "0.30.0"

Usage

use {
    graaf::{
        algo::bfs::single_pair_shortest_path,
        op::{
            AddEdge,
            Indegree,
        },
    },
    std::collections::HashSet,
};

let mut graph = [
    HashSet::new(), 
    HashSet::new(), 
    HashSet::new(), 
    HashSet::new()
];

// ╭───╮     ╭───╮
// │ 0 │  →  │ 1 │
// ╰───╯     ╰───╯
//   ↑         ↓
// ╭───╮     ╭───╮
// │ 3 │     │ 2 │
// ╰───╯     ╰───╯

graph.add_edge(3, 0);
graph.add_edge(0, 1);
graph.add_edge(1, 2);

assert_eq!(graph.indegree(0), 1);
assert_eq!(graph.indegree(1), 1);
assert_eq!(graph.indegree(2), 1);
assert_eq!(graph.indegree(3), 0);

let path = single_pair_shortest_path(&graph, 3, 2);

assert_eq!(path, Some(vec![3, 0, 1, 2]));

Features

adjacency_matrix

This feature enables AdjacencyMatrix, which requires nightly Rust. To disable, change the [dependencies] entry for graaf in your Cargo.toml:

[dependencies]
graaf = { version = "0.30.0", default-features = false }