simplegraph/visitor.rs
1/*!
2 * Common interface to access a graph's topology.
3 */
4
5/**
6 * Visit a graph's inner topology with callbacks.
7 */
8pub trait GraphVisitor<N>
9where
10 N: Copy,
11{
12 /**
13 * Call function *f* for each node in the graph.
14 * At each call the first argument is a node's index
15 * and the second is the current node weight.
16 */
17 fn node_visitor<F: FnMut(usize, N)>(&self, f: F);
18
19 /**
20 * Call function *g* for each arc in the graph.
21 * At each call the first argument is the source node index,
22 * the second is destination node index and the third the current arc weight.
23 */
24 fn arc_visitor<G: FnMut(usize, usize, N)>(&self, g: G);
25
26 /**
27 * Return the number of nodes in the graph.
28 */
29 fn node_count(&self) -> usize;
30
31 /**
32 * Return the number of arcs in the graph.
33 */
34 fn arc_count(&self) -> usize;
35
36 /**
37 * Return the total number of nodes and arcs in the
38 * graph.
39 */
40 fn total_entries(&self) -> usize {
41 self.arc_count() + self.node_count()
42 }
43}