in src/dachshund/simple_directed_graph.rs [25:43]
fn is_acyclic(&self) -> bool {
// from https://www.cs.hmc.edu/~keller/courses/cs60/s98/examples/acyclic/
let mut leaves: HashSet<NodeId> = HashSet::new();
let num_nodes = self.count_nodes();
while leaves.len() < num_nodes {
let mut leaf_was_found: bool = false;
for node in self.get_nodes_iter() {
let node_id = node.get_id();
if !leaves.contains(&node_id) && node.has_no_out_neighbors_except_set(&leaves) {
leaves.insert(node.get_id());
leaf_was_found = true;
}
}
if !leaf_was_found {
return false;
}
}
true
}