Skip to main content

Module back_edges

Module back_edges 

Source
Expand description

The back edges of a graph: the edges that a depth-first search finds pointing back to a node on its current path, self-loops included - Java’s class BackEdges.

Every cycle contains a back edge, so a graph without back edges is a DAG (directed acyclic graph), and removing the back edges of a graph leaves a DAG. They form a feedback arc set, though not in general a smallest one.

Uses the depth-first search of EdgeTypes::of, without recursion: of finds the edges that EdgeTypes classifies as EdgeType::Back, without classifying the others.

use graphity_core::{back_edges, GraphBuilder};

let mut b = GraphBuilder::new();
b.add_nodes(4);
b.add_path(&[0, 1, 2, 3, 0]);
let back = back_edges::of(&b.build());
assert_eq!((back.source_nodes(), back.target_nodes()), (&[3][..], &[0][..]));

Functions§

of
Returns the back edges of graph, in the order in which the search finds them.