Add graph::depth_first_search_as_undirected
This commit is contained in:
parent
7d2cb3dda7
commit
fa134b5e0f
@ -52,3 +52,29 @@ where
|
|||||||
{
|
{
|
||||||
iterate::DepthFirstSearch::new(graph).with_start_node(from)
|
iterate::DepthFirstSearch::new(graph).with_start_node(from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn depth_first_search_as_undirected<G>(
|
||||||
|
graph: G,
|
||||||
|
from: G::Node,
|
||||||
|
) -> iterate::DepthFirstSearch<impl Successors<Node = G::Node>>
|
||||||
|
where
|
||||||
|
G: Successors + Predecessors,
|
||||||
|
{
|
||||||
|
struct AsUndirected<G>(G);
|
||||||
|
|
||||||
|
impl<G: DirectedGraph> DirectedGraph for AsUndirected<G> {
|
||||||
|
type Node = G::Node;
|
||||||
|
|
||||||
|
fn num_nodes(&self) -> usize {
|
||||||
|
self.0.num_nodes()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<G: Successors + Predecessors> Successors for AsUndirected<G> {
|
||||||
|
fn successors(&self, node: Self::Node) -> impl Iterator<Item = Self::Node> {
|
||||||
|
self.0.successors(node).chain(self.0.predecessors(node))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iterate::DepthFirstSearch::new(AsUndirected(graph)).with_start_node(from)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user