Make depth_first_search into a standalone function

Does not necessarily change much, but we never overwrite it, so I see no reason
for it to be in the `Successors` trait. (+we already have a similar `is_cyclic`)
This commit is contained in:
Maybe Waffle
2024-04-14 16:03:08 +00:00
parent 3124fa9310
commit e8d2221e3b
6 changed files with 21 additions and 17 deletions

View File

@@ -30,10 +30,6 @@ pub trait Successors: DirectedGraph {
Self: 'g;
fn successors(&self, node: Self::Node) -> Self::Successors<'_>;
fn depth_first_search(&self, from: Self::Node) -> iterate::DepthFirstSearch<'_, Self> {
iterate::DepthFirstSearch::new(self).with_start_node(from)
}
}
pub trait Predecessors: DirectedGraph {
@@ -57,3 +53,10 @@ where
.run_from_start(&mut iterate::CycleDetector)
.is_some()
}
pub fn depth_first_search<G>(graph: &G, from: G::Node) -> iterate::DepthFirstSearch<'_, G>
where
G: ?Sized + Successors,
{
iterate::DepthFirstSearch::new(graph).with_start_node(from)
}