1+ use std:: iter:: once;
2+
13// TODO: Somebody, adopt this code to `petgraph`.
24use petgraph:: { data:: DataMap , visit:: { Bfs , Dfs , IntoNeighbors , VisitMap } } ;
35
@@ -25,7 +27,7 @@ impl<NodeId, VM> DfsFiltered<NodeId, VM> {
2527 {
2628 while let Some ( source_item_id) = & self . base . next ( graph) {
2729 if ( & mut predicate) ( source_item_id) {
28- let source_parent_id = self . base . stack . iter ( ) . map ( |e| * e) . rev ( ) . find ( & mut predicate) ;
30+ let source_parent_id = self . base . stack . iter ( ) . map ( |e| * e) . rev ( ) . find ( & mut predicate) ; // FIXME: `rev()` here?
2931 if let Some ( source_parent_id) = & source_parent_id {
3032 ( & mut call) ( source_parent_id, & source_item_id) ;
3133 }
@@ -50,14 +52,17 @@ impl<NodeId, VM> BfsFiltered<NodeId, VM> {
5052 where C : FnMut ( & NodeId , & NodeId ) -> ( ) ,
5153 G : IntoNeighbors < NodeId = NodeId > + DataMap < NodeWeight = NodeWeight > ,
5254 P : FnMut ( & NodeId ) -> bool ,
53- NodeId : Copy + Eq ,
55+ NodeId : Copy + Eq + std :: fmt :: Debug , // TODO: Remove debug.
5456 VM : VisitMap < NodeId > ,
5557 {
56- while let Some ( source_item_id) = & self . base . next ( graph) {
57- if ( & mut predicate) ( source_item_id) {
58- let source_parent_id = self . base . stack . iter ( ) . map ( |e| * e) . rev ( ) . find ( & mut predicate) ;
59- if let Some ( source_parent_id) = & source_parent_id {
60- ( & mut call) ( source_parent_id, & source_item_id) ;
58+ if let Some ( first_id) = self . base . next ( graph) {
59+ while let Some ( source_child_id) = & self . base . next ( graph) {
60+ if ( & mut predicate) ( source_child_id) {
61+ let source_parent_id = self . base . stack . iter ( ) . map ( |e| * e) . chain ( once ( first_id) ) . find ( & mut predicate) ;
62+ if let Some ( source_parent_id) = & source_parent_id {
63+ println ! ( "YYY: {:?} => {:?}" , source_parent_id, & source_child_id) ;
64+ ( & mut call) ( source_parent_id, & source_child_id) ;
65+ }
6166 }
6267 }
6368 }
0 commit comments