Macro fera_graph::graph [] [src]

macro_rules! graph {
    () => { ... };
    ($n:expr) => { ... };
    ($n:expr, $(($u:expr, $v:expr)),+) => { ... };
    ($n:expr, $(($u:expr, $v:expr)),+,) => { ... };
    ($n:expr, $(($u:expr, $v:expr) -> $p:expr),+) => { ... };
    ($n:expr, $(($u:expr, $v:expr) -> $p:expr),+,) => { ... };
}

Creates a new graph with n vertices and the specified edges.

The type of the graph that will be created needs to be specified. Any graph that implements Builder can be used. There are two forms of this macro:

  • Creates a graph with a list of edges:
#[macro_use] extern crate fera_graph;
use fera_graph::prelude::*;

let g: StaticGraph = graph!{
    4,
    (0, 2),
    (0, 3),
    (1, 2)
};

assert_eq!(4, g.num_vertices());
assert_eq!(3, g.num_edges());

for u in 0..4 {
    for v in 0..4 {
        if [(0, 2), (2, 0), (0, 3), (3, 0), (1, 2), (2, 1)].contains(&(u, v)) {
            assert_eq!(g.end_vertices(g.edge_by_ends(u, v)), (u, v));
        } else {
            assert_eq!(None, g.get_edge_by_ends(u, v));
        }
    }
}
  • Creates a graph with a list of edges and an associated property:
#[macro_use] extern crate fera_graph;
use fera_graph::prelude::*;
use fera_graph::sum_prop;

let (g, w): (StaticGraph, _) = graph!{
    4,
    (0, 2) -> 4,
    (0, 3) -> 2,
    (1, 2) -> 3
};

assert_eq!(9, sum_prop(&w, g.edges()));

In this case, a DefaultEdgePropMut is created.