1
+ use std:: iter:: once;
2
+
1
3
// TODO: Somebody, adopt this code to `petgraph`.
2
4
use petgraph:: { data:: DataMap , visit:: { Bfs , Dfs , IntoNeighbors , VisitMap } } ;
3
5
@@ -25,7 +27,7 @@ impl<NodeId, VM> DfsFiltered<NodeId, VM> {
25
27
{
26
28
while let Some ( source_item_id) = & self . base . next ( graph) {
27
29
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?
29
31
if let Some ( source_parent_id) = & source_parent_id {
30
32
( & mut call) ( source_parent_id, & source_item_id) ;
31
33
}
@@ -50,14 +52,17 @@ impl<NodeId, VM> BfsFiltered<NodeId, VM> {
50
52
where C : FnMut ( & NodeId , & NodeId ) -> ( ) ,
51
53
G : IntoNeighbors < NodeId = NodeId > + DataMap < NodeWeight = NodeWeight > ,
52
54
P : FnMut ( & NodeId ) -> bool ,
53
- NodeId : Copy + Eq ,
55
+ NodeId : Copy + Eq + std :: fmt :: Debug , // TODO: Remove debug.
54
56
VM : VisitMap < NodeId > ,
55
57
{
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
+ }
61
66
}
62
67
}
63
68
}
0 commit comments