11// Copyright (c) "2023" . Marvin Hansen <[email protected] > All rights reserved. 22use std:: collections:: HashMap ;
3- use crate :: errors:: CausalityGraphError ;
4- use crate :: prelude:: { Causable , IdentificationValue , NodeIndex , NumericalValue } ;
3+ use crate :: errors:: { CausalGraphIndexError , CausalityGraphError } ;
4+ use crate :: prelude:: { Causable , IdentificationValue , NumericalValue } ;
55
66pub trait CausableGraph < T >
77 where
88 T : Causable + PartialEq ,
99{
1010 // Root Node
11- fn add_root_causaloid ( & mut self , value : T ) -> NodeIndex ;
11+ fn add_root_causaloid ( & mut self , value : T ) -> usize ;
1212 fn contains_root_causaloid ( & self ) -> bool ;
1313 fn get_root_causaloid ( & self ) -> Option < & T > ;
14- fn get_root_index ( & self ) -> Option < NodeIndex > ;
15- fn get_last_index ( & self ) -> Result < NodeIndex , CausalityGraphError > ;
14+ fn get_root_index ( & self ) -> Option < usize > ;
15+ fn get_last_index ( & self ) -> Result < usize , CausalityGraphError > ;
1616
1717 // Nodes
18- fn add_causaloid ( & mut self , value : T ) -> NodeIndex ;
19- fn contains_causaloid ( & self , index : NodeIndex ) -> bool ;
20- fn get_causaloid ( & self , index : NodeIndex ) -> Option < & T > ;
21- fn remove_causaloid ( & mut self , index : NodeIndex ) ;
18+ fn add_causaloid ( & mut self , value : T ) -> usize ;
19+ fn contains_causaloid ( & self , index : usize ) -> bool ;
20+ fn get_causaloid ( & self , index : usize ) -> Option < & T > ;
21+ fn remove_causaloid ( & mut self , index : usize ) -> Result < ( ) , CausalGraphIndexError >
22+ ;
2223
2324 // Edges
24- fn add_edge ( & mut self , a : NodeIndex , b : NodeIndex ) ;
25- fn add_edg_with_weight ( & mut self , a : NodeIndex , b : NodeIndex , weight : u64 ) ;
25+ fn add_edge ( & mut self , a : usize , b : usize ) -> Result < ( ) , CausalGraphIndexError > ;
26+ fn add_edg_with_weight ( & mut self , a : usize , b : usize , weight : u64 ) -> Result < ( ) , CausalGraphIndexError > ;
2627
27- fn contains_edge ( & self , a : NodeIndex , b : NodeIndex ) -> bool ;
28- fn remove_edge ( & mut self , a : NodeIndex , b : NodeIndex ) ;
28+ fn contains_edge ( & self , a : usize , b : usize ) -> bool ;
29+ fn remove_edge ( & mut self , a : usize , b : usize ) -> Result < ( ) , CausalGraphIndexError > ;
2930
3031 // Utils
3132 fn all_active ( & self ) -> bool ;
@@ -60,7 +61,7 @@ pub trait CausableGraphReasoning<T>
6061 /// Returns: String representing the explanation or an error
6162 fn explain_subgraph_from_cause (
6263 & self ,
63- start_index : NodeIndex ,
64+ start_index : usize ,
6465 )
6566 -> Result < String , CausalityGraphError > ;
6667
@@ -74,8 +75,8 @@ pub trait CausableGraphReasoning<T>
7475 /// Returns: String representing the explanation or an error
7576 fn explain_shortest_path_between_causes (
7677 & self ,
77- start_index : NodeIndex ,
78- stop_index : NodeIndex ,
78+ start_index : usize ,
79+ stop_index : usize ,
7980 )
8081 -> Result < String , CausalityGraphError > ;
8182
@@ -115,7 +116,7 @@ pub trait CausableGraphReasoning<T>
115116 /// a CausalityGraphError in case of failure.
116117 fn reason_subgraph_from_cause (
117118 & self ,
118- start_index : NodeIndex ,
119+ start_index : usize ,
119120 data : & [ NumericalValue ] ,
120121 data_index : Option < & HashMap < IdentificationValue , IdentificationValue > > ,
121122 )
@@ -138,8 +139,8 @@ pub trait CausableGraphReasoning<T>
138139 /// a CausalityGraphError in case of failure.
139140 fn reason_shortest_path_between_causes (
140141 & self ,
141- start_index : NodeIndex ,
142- stop_index : NodeIndex ,
142+ start_index : usize ,
143+ stop_index : usize ,
143144 data : & [ NumericalValue ] ,
144145 data_index : Option < & HashMap < IdentificationValue , IdentificationValue > > ,
145146 )
@@ -153,7 +154,7 @@ pub trait CausableGraphReasoning<T>
153154 /// a CausalityGraphError in case of failure.
154155 fn reason_single_cause (
155156 & self ,
156- index : NodeIndex ,
157+ index : usize ,
157158 data : & [ NumericalValue ] ,
158159 )
159160 -> Result < bool , CausalityGraphError > ;
0 commit comments