@@ -5,17 +5,17 @@ use the_module::abs;
55use iter_tools:: { _IterTrait, IterTrait , BoxedIter } ;
66
77#[ derive( Debug ) ]
8- pub struct Node < ' a >
8+ pub struct Node
99{
1010 pub id : NodeId ,
11- pub children : Vec < & ' a Node < ' a > > ,
11+ pub children : Vec < NodeId > ,
1212}
1313
14- impl < ' a > the_module:: abs:: Node for Node < ' a > { }
14+ impl the_module:: abs:: Node for Node { }
1515
16- impl < ' a > Node < ' a >
16+ impl Node
1717{
18- pub fn new < IntoId : Into < NodeId > > ( id : IntoId ) -> Node < ' a >
18+ pub fn new < IntoId : Into < NodeId > > ( id : IntoId ) -> Node
1919 {
2020 Node
2121 {
@@ -24,23 +24,23 @@ impl< 'a > Node< 'a >
2424 }
2525 }
2626
27- pub fn add_child ( & mut self , child : & ' a Node < ' a > ) -> & mut Self
27+ pub fn add_child ( & mut self , child : & Node ) -> & mut Self
2828 {
29- self . children . push ( child ) ;
29+ self . children . push ( child. id ) ;
3030 self
3131 }
3232}
3333
3434#[ derive( Default ) ]
3535pub struct Graph < ' a >
3636{
37- nodes : HashMap < NodeId , & ' a Node < ' a > > ,
37+ nodes : HashMap < NodeId , & ' a Node > ,
3838}
3939
4040impl < ' a > Graph < ' a >
4141{
4242
43- pub fn add_node ( & mut self , node : & ' a Node < ' a > )
43+ pub fn add_node ( & mut self , node : & ' a Node )
4444 {
4545 self . nodes . insert ( node. id , node ) ;
4646 }
@@ -51,14 +51,14 @@ impl< 'a > abs::GraphDirected< 'a > for Graph< 'a >
5151{
5252
5353 type NodeId = NodeId ;
54- type Node = Node < ' a > ;
54+ type Node = Node ;
5555
56- fn node_ref ( & self , node_id : NodeId ) -> & ' a Node < ' a >
56+ fn node_ref ( & self , node_id : NodeId ) -> & ' a Node
5757 {
5858 self . nodes . get ( & node_id ) . expect ( "If id exist then node shoudl also exist" )
5959 }
6060
61- fn node_id ( & self , node : & ' a Node < ' a > ) -> NodeId
61+ fn node_id ( & self , node : & Node ) -> NodeId
6262 {
6363 node. id
6464 }
@@ -67,7 +67,7 @@ impl< 'a > abs::GraphDirected< 'a > for Graph< 'a >
6767 {
6868 if let Some ( node ) = self . nodes . get ( & node_id )
6969 {
70- Box :: new ( node. children . iter ( ) . map ( | child | child . id ) )
70+ Box :: new ( node. children . iter ( ) . cloned ( ) )
7171 }
7272 else
7373 {
@@ -80,3 +80,33 @@ impl< 'a > abs::GraphDirected< 'a > for Graph< 'a >
8080pub struct NodeId ( usize ) ;
8181
8282impl the_module:: abs:: NodeId for NodeId { }
83+
84+ // xxx
85+
86+ impl < ' a > Graph < ' a >
87+ {
88+
89+ // pub fn duplet() -> ( Vec< Node >, Self )
90+ // {
91+ //
92+ // // Create nodes
93+ // let mut nodes_darray : Vec< Node > = vec![ 1, 2, 3 ].into_iter().map( | id | Node::new( id ) ).collect();
94+ // let mut node1 = Node::new( 1 );
95+ // let node2 = Node::new( 2 );
96+ // let node3 = Node::new( 3 );
97+ //
98+ // // Set up the graph structure
99+ // node1
100+ // .add_child( &node2 )
101+ // .add_child( &node3 )
102+ // ;
103+ //
104+ // let mut graph = Self::default();
105+ // graph.add_node( &node1 );
106+ // graph.add_node( &node2 );
107+ // graph.add_node( &node3 );
108+ //
109+ // return ( nodes_darray, graph );
110+ // }
111+
112+ }
0 commit comments