Skip to content

Commit 29edb52

Browse files
committed
graphs tools : refactor
1 parent 4ae6ec0 commit 29edb52

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

module/move/graphs_tools/src/abs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ mod private
6666

6767
/// Iterate over out nodes of
6868
fn node_out_nodes( &'a self, node_id : Self::NodeId ) -> BoxedIter< 'a, Self::NodeId >;
69-
// fn node_out_nodes( &self, node_id : Self::NodeId ) -> impl _IterTrait< 'a, Self::NodeId >;
7069

7170
}
7271

module/move/graphs_tools/tests/inc/graph/map_of_nodes.rs

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ impl Node
2424
}
2525
}
2626

27-
pub fn add_child( &mut self, child : &Node ) -> &mut Self
27+
pub fn child_add( &mut self, child : &Node ) -> &mut Self
2828
{
2929
self.children.push( child.id );
3030
self
3131
}
32+
33+
pub fn children_add< 'a, I >( &mut self, nodes : I ) -> &mut Self
34+
where
35+
I : IntoIterator< Item = &'a Node >,
36+
{
37+
for node in nodes
38+
{
39+
self.children.push( node.id );
40+
}
41+
self
42+
}
43+
3244
}
3345

3446
#[ derive( Default ) ]
@@ -40,11 +52,22 @@ pub struct Graph
4052
impl Graph
4153
{
4254

43-
pub fn add_node( &mut self, node : Node )
55+
pub fn node_add( &mut self, node : Node )
4456
{
4557
self.nodes.insert( node.id, node );
4658
}
4759

60+
pub fn nodes_add< 'a, I >( &mut self, nodes : I ) -> &mut Self
61+
where
62+
I : IntoIterator< Item = Node >,
63+
{
64+
for node in nodes
65+
{
66+
self.nodes.insert( node.id, node );
67+
}
68+
self
69+
}
70+
4871
}
4972

5073
impl< 'a > abs::GraphDirected< 'a > for Graph
@@ -96,15 +119,28 @@ impl Graph
96119
let node2 = Node::new( 2 );
97120

98121
// Set up the graph structure
99-
node0
100-
.add_child( &node1 )
101-
.add_child( &node2 )
102-
;
122+
node0.children_add([ &node1, &node2 ]);
123+
124+
let mut graph = Self::default();
125+
graph.nodes_add([ node0, node1, node2 ]);
126+
127+
graph
128+
}
129+
130+
pub fn duplet_assymetric() -> Self
131+
{
132+
133+
// Create nodes
134+
let mut node0 = Node::new( 0 );
135+
let node1 = Node::new( 1 );
136+
let mut node2 = Node::new( 2 );
137+
let node3 = Node::new( 3 );
138+
139+
node0.children_add([ &node1, &node2 ]);
140+
node2.children_add([ &node3 ]);
103141

104142
let mut graph = Self::default();
105-
graph.add_node( node0 );
106-
graph.add_node( node1 );
107-
graph.add_node( node2 );
143+
graph.nodes_add([ node0, node1, node2, node3 ]);
108144

109145
graph
110146
}

module/move/graphs_tools/tests/inc/nodes_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// }
2121
// }
2222
//
23-
// fn add_child( &mut self, child : &'a Node< 'a > ) -> &mut Self
23+
// fn child_add( &mut self, child : &'a Node< 'a > ) -> &mut Self
2424
// {
2525
// self.children.push( child );
2626
// self
@@ -87,9 +87,9 @@
8787
// let node4 = Node::new( NodeId( 4 ) );
8888
//
8989
// node1
90-
// .add_child( &node2 )
91-
// .add_child( &node3 )
92-
// .add_child( &node4 );
90+
// .child_add( &node2 )
91+
// .child_add( &node3 )
92+
// .child_add( &node4 );
9393
//
9494
// let mut graph = Graph::new();
9595
// graph.add_node( &node1 );

module/move/graphs_tools/tests/inc/search_test/dfs_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use graph::map_of_nodes::
3232
// }
3333
// }
3434
//
35-
// fn add_child( &mut self, child : &'a Node< 'a > ) -> &mut Self
35+
// fn child_add( &mut self, child : &'a Node< 'a > ) -> &mut Self
3636
// {
3737
// self.children.push( child );
3838
// self

0 commit comments

Comments
 (0)