Skip to content

Commit 5318aa9

Browse files
committed
graphs_tools: search methods working
1 parent 541baf8 commit 5318aa9

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

module/move/graphs_tools/src/abs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ crate::mod_interface!
7676
{
7777
own use
7878
{
79-
_IterTrait,
79+
// _IterTrait,
8080
IdentityInterface,
8181
NodeId,
8282
Node,

module/move/graphs_tools/src/search.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
mod private
22
{
3+
4+
// xxx : write setters and default
35
/// Options for configuring a graph search.
46
#[ derive( Debug ) ]
5-
pub struct Options< 'a, Method, NodeId, Node, Visit >
7+
pub struct Options< 'a, Method, Graph, Visit >
68
where
7-
NodeId : crate::abs::NodeId,
8-
Node : crate::abs::Node + 'a,
9-
Visit : FnMut( &'a Node ),
9+
Graph : crate::abs::GraphDirected< 'a > + ?Sized,
10+
// NodeId : Graph::NodeId,
11+
// Node : Graph::Node + 'a,
12+
Visit : FnMut( &'a Graph::Node ),
1013
Method : super::Method,
1114
{
1215
/// Starting node ID for the search.
13-
pub start_id : NodeId,
16+
pub start_id : Graph::NodeId,
1417
/// Function to call on each visited node.
1518
pub visit : Visit,
1619
/// Additional options specific to the search method.
1720
pub _extra : Method::ExtraOptions,
1821
/// Phantom data to associate types and lifetimes.
19-
pub _phantom : std::marker::PhantomData< ( Method, Node, &'a () ) >,
22+
pub _phantom : std::marker::PhantomData< ( Method, Graph::Node, &'a () ) >,
2023
}
2124

2225
/// Trait for performing searches on directed graphs.
@@ -26,7 +29,7 @@ mod private
2629
fn search< Visit, Method >
2730
(
2831
&'a self,
29-
o : Options< 'a, Method, Self::NodeId, Self::Node, Visit >,
32+
o : Options< 'a, Method, Self, Visit >,
3033
)
3134
where
3235
Visit : FnMut( &'a Self::Node ),
@@ -52,7 +55,7 @@ mod private
5255
fn _search< 'a, Graph, Visit >
5356
(
5457
graph : &'a Graph,
55-
o : Options< 'a, Self, Graph::NodeId, Graph::Node, Visit >,
58+
o : Options< 'a, Self, Graph, Visit >,
5659
)
5760
where
5861
Visit : FnMut( &'a Graph::Node ),
@@ -72,7 +75,7 @@ mod private
7275
fn _search< 'a, Graph, Visit >
7376
(
7477
graph : &'a Graph,
75-
mut o : Options< 'a, Self, Graph::NodeId, Graph::Node, Visit >,
78+
mut o : Options< 'a, Self, Graph, Visit >,
7679
)
7780
where
7881
Visit : FnMut( &'a Graph::Node ),
@@ -109,7 +112,7 @@ mod private
109112
fn _search< 'a, Graph, Visit >
110113
(
111114
graph : &'a Graph,
112-
mut o : Options< 'a, Self, Graph::NodeId, Graph::Node, Visit >,
115+
mut o : Options< 'a, Self, Graph, Visit >,
113116
)
114117
where
115118
Visit : FnMut( &'a Graph::Node ),
@@ -133,6 +136,7 @@ mod private
133136
}
134137
}
135138
}
139+
136140
}
137141

138142
crate::mod_interface!

module/move/graphs_tools/tests/inc/search/dfs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,19 @@ fn test_dfs()
126126
};
127127

128128
// Create search options
129-
let search_options : search::Options< '_, search::Dfs, _, _, _ > = search::Options
129+
let search_options : search::Options< '_, search::Dfs, _, _ > = search::Options
130+
// let search_options = search::Options
130131
{
131132
start_id : NodeId( 1 ),
132133
visit,
133134
_extra : (),
134135
_phantom : std::marker::PhantomData,
135136
};
136137

137-
// xxx
138-
// // Perform DFS
139-
// graph.search( search_options );
140-
//
141-
// // Assert the order of visited nodes
142-
// assert_eq!( visited_nodes, vec![ NodeId( 1 ), NodeId( 4 ), NodeId( 3 ), NodeId( 2 ) ] );
138+
// Perform DFS
139+
graph.search( search_options );
140+
141+
// Assert the order of visited nodes
142+
assert_eq!( visited_nodes, vec![ NodeId( 1 ), NodeId( 4 ), NodeId( 3 ), NodeId( 2 ) ] );
143143

144144
}

0 commit comments

Comments
 (0)