File tree 1 file changed +26
-0
lines changed
compiler/rustc_data_structures/src/graph
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 52
52
{
53
53
iterate:: DepthFirstSearch :: new ( graph) . with_start_node ( from)
54
54
}
55
+
56
+ pub fn depth_first_search_as_undirected < G > (
57
+ graph : G ,
58
+ from : G :: Node ,
59
+ ) -> iterate:: DepthFirstSearch < impl Successors < Node = G :: Node > >
60
+ where
61
+ G : Successors + Predecessors ,
62
+ {
63
+ struct AsUndirected < G > ( G ) ;
64
+
65
+ impl < G : DirectedGraph > DirectedGraph for AsUndirected < G > {
66
+ type Node = G :: Node ;
67
+
68
+ fn num_nodes ( & self ) -> usize {
69
+ self . 0 . num_nodes ( )
70
+ }
71
+ }
72
+
73
+ impl < G : Successors + Predecessors > Successors for AsUndirected < G > {
74
+ fn successors ( & self , node : Self :: Node ) -> impl Iterator < Item = Self :: Node > {
75
+ self . 0 . successors ( node) . chain ( self . 0 . predecessors ( node) )
76
+ }
77
+ }
78
+
79
+ iterate:: DepthFirstSearch :: new ( AsUndirected ( graph) ) . with_start_node ( from)
80
+ }
You can’t perform that action at this time.
0 commit comments