graaf 0.35.4

Functions and types for working with graphs
Documentation
# ![Graaf!]/logo.png "Graaf"   [![Crates.io]https://img.shields.io/crates/v/graaf.svg]https://crates.io/crates/graaf [![Build status]https://github.com/bsdrks/graaf/actions/workflows/rust.yml/badge.svg]https://github.com/bsdrks/graaf/actions [![API reference]https://docs.rs/graaf/badge.svg]https://docs.rs/graaf [![Coverage Status]https://coveralls.io/repos/github/bsdrks/graaf/badge.svg?branch=main]https://coveralls.io/github/bsdrks/graaf?branch=main

Algorithms, operations, generators, and representations for directed graphs

## Installation

Add the following to your `Cargo.toml`:

```toml
[dependencies]
graaf = "0.35.4"
```

To use stable Rust, turn off the `adjacency_matrix` feature:

```toml
[dependencies]
graaf = { version = "0.35.4", default-features = false }
```

## Overview

### Operations

```rust
use {
    graaf::{
        gen::EmptyConst,
        op::{
            AddEdge,
            Indegree,
            Outdegree,
            RemoveEdge,
        },
    },
    std::collections::BTreeSet,
};

let mut graph = <[BTreeSet<usize>; 3]>::empty();

// 1 ← 0 → 2

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

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

graph.remove_edge(0, 1);

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

### Algorithms

Search, traverse, and analyze graphs built from the types that implement the
operation traits.

```rust
use graaf::algo::bfs::single_pair_shortest_path as spsp;

// 0  ←  1
// ↑     ↑
// 3  →  2

let graph = [Vec::new(), vec![0], vec![1], vec![0, 2]];

assert_eq!(spsp(&graph, 3, 0), Some(vec![3, 0]));
assert_eq!(spsp(&graph, 3, 1), Some(vec![3, 2, 1]));
assert_eq!(spsp(&graph, 3, 2), Some(vec![3, 2]));
assert_eq!(spsp(&graph, 0, 3), None);
```

### Representations

Use custom graph representations. An adjacency matrix representation is
available with the `adjacency_matrix` feature.

```rust
use graaf::{
    op::{
        AddEdge,
        IsSimple,
    },
    repr::AdjacencyMatrix,
};

let mut graph = AdjacencyMatrix::<3>::new();

graph.add_edge(0, 1);

assert!(graph.is_simple());

graph.add_edge(1, 1);

assert!(!graph.is_simple());
```

### Generators

Generate parameterized graphs.

```rust
use graaf::gen::Cycle;

let graph = Vec::<Vec<usize>>::cycle(5);

assert_eq!(graph, vec![vec![1], vec![2], vec![3], vec![4], vec![0]]);
```

## Changelog

See [CHANGELOG.md](https://github.com/bsdrks/graaf/blob/main/CHANGELOG.md).

## License

Licensed under either the [Apache License, Version 2.0] or the [MIT license] at your option.

[Apache License, Version 2.0]: LICENSE-APACHE
[MIT license]: LICENSE-MIT