@@ -52,22 +52,22 @@ where
5252 G :: NodeId : Eq + Hash ,
5353 G :: EdgeId : Eq + Hash ,
5454{
55- let mut root_node = root;
55+ let mut root_node: Option < G :: NodeId > = root;
5656 let mut graph_nodes: HashSet < G :: NodeId > = graph. node_identifiers ( ) . collect ( ) ;
5757 let mut cycles_edges: Vec < Vec < G :: EdgeId > > = Vec :: new ( ) ;
5858 let mut cycles_nodes: Vec < Vec < G :: NodeId > > = Vec :: new ( ) ;
5959
60- // Method used to retrieve all the edges between an origin node and a target node.
61- // Can be used to check if a node loops back to itself by enabling equiv
62- fn get_edge_between < G > ( orig_graph : G , origin : G :: NodeId , target : G :: NodeId ) -> Vec < G :: EdgeId >
60+ /// Method used to retrieve all the edges between an origin node and a target node.
61+ fn get_edge_between < G > ( orig_graph : G , origin : G :: NodeId , target : G :: NodeId ) -> G :: EdgeId
6362 where
6463 G : IntoEdges ,
6564 {
6665 orig_graph
6766 . edges ( origin)
6867 . filter ( |edge : & G :: EdgeRef | edge. target ( ) == target)
6968 . map ( |edge : G :: EdgeRef | edge. id ( ) )
70- . collect ( )
69+ . next ( )
70+ . unwrap ( )
7171 }
7272
7373 while !graph_nodes. is_empty ( ) {
@@ -105,7 +105,7 @@ where
105105 // A self loop:
106106 } else if z == neighbor {
107107 if edges {
108- let cycle_edge: Vec < G :: EdgeId > = get_edge_between ( graph, z, z) ;
108+ let cycle_edge: Vec < G :: EdgeId > = vec ! [ get_edge_between( graph, z, z) ] ;
109109 cycles_edges. push ( cycle_edge) ;
110110 } else {
111111 let cycle: Vec < G :: NodeId > = vec ! [ z] ;
@@ -117,31 +117,24 @@ where
117117 let mut p = pred. get ( & z) . unwrap ( ) ;
118118 if edges {
119119 let mut cycle: Vec < G :: EdgeId > = Vec :: new ( ) ;
120- // Retreive all edges from z to neighbor.
121- let mut neigh_edge: Vec < G :: EdgeId > = get_edge_between ( graph, z, neighbor) ;
122- // Append to cycle
123- cycle. append ( & mut neigh_edge) ;
120+ // Retreive all edges from z to neighbor and push to cycle
121+ cycle. push ( get_edge_between ( graph, z, neighbor) ) ;
124122
125123 // Make last p_node == z
126124 let mut prev_p: & G :: NodeId = & z;
127125 // While p is in the neighborhood of neighbor
128126 while !pn. contains ( p) {
129- // Retrieve all edges from prev_p to p and vice versa
130- let mut neigh_edge: Vec < G :: EdgeId > =
131- get_edge_between ( graph, * prev_p, * p) ;
132- // Append to cycle
133- cycle. append ( & mut neigh_edge) ;
127+ // Retrieve all edges from prev_p to p and vice versa append to cycle
128+ cycle. push ( get_edge_between ( graph, * prev_p, * p) ) ;
134129 // Update prev_p to p
135130 prev_p = p;
136131 // Retreive a new predecessor node from p and replace p
137132 p = pred. get ( p) . unwrap ( ) ;
138133 }
139134 // When loop ends add remaining edges from prev_p to p.
140- let mut neigh_edge: Vec < G :: EdgeId > = get_edge_between ( graph, * prev_p, * p) ;
141- cycle. append ( & mut neigh_edge) ;
135+ cycle. push ( get_edge_between ( graph, * prev_p, * p) ) ;
142136 // Also retreive all edges between the last p and neighbor
143- let mut neigh_edge: Vec < G :: EdgeId > = get_edge_between ( graph, * p, neighbor) ;
144- cycle. append ( & mut neigh_edge) ;
137+ cycle. push ( get_edge_between ( graph, * p, neighbor) ) ;
145138 // Once all edges within cycle have been found, push to cycle list.
146139 cycles_edges. push ( cycle) ;
147140 } else {
0 commit comments