@@ -733,13 +733,6 @@ impl<'a> Display for DisplaySymbolStackKey<'a> {
733
733
//-------------------------------------------------------------------------------------------------
734
734
// Stitching partial paths together
735
735
736
- /// Configuration for partial path stitchers.
737
- #[ derive( Clone , Debug , Default ) ]
738
- pub struct StitcherConfig {
739
- /// Enables similar path detection during path stitching.
740
- pub detect_similar_paths : bool ,
741
- }
742
-
743
736
/// Implements a phased forward partial path stitching algorithm.
744
737
///
745
738
/// Our overall goal is to start with a set of _seed_ partial paths, and to repeatedly extend each
@@ -796,7 +789,6 @@ impl<H> ForwardPartialPathStitcher<H> {
796
789
_graph : & StackGraph ,
797
790
_partials : & mut PartialPaths ,
798
791
initial_partial_paths : I ,
799
- config : & StitcherConfig ,
800
792
) -> Self
801
793
where
802
794
I : IntoIterator < Item = PartialPath > ,
@@ -809,16 +801,14 @@ impl<H> ForwardPartialPathStitcher<H> {
809
801
( p, c, false )
810
802
} )
811
803
. multiunzip ( ) ;
812
- let similar_path_detector =
813
- Some ( SimilarPathDetector :: new ( ) ) . filter ( |_| config. detect_similar_paths ) ;
814
- ForwardPartialPathStitcher {
804
+ Self {
815
805
candidates : Vec :: new ( ) ,
816
806
extensions : Vec :: new ( ) ,
817
807
queue : VecDeque :: new ( ) ,
818
808
initial_paths : next_iteration. 0 . len ( ) ,
819
809
next_iteration,
820
810
appended_paths,
821
- similar_path_detector,
811
+ similar_path_detector : Some ( SimilarPathDetector :: new ( ) ) ,
822
812
// By default, all nodes are checked for cycles and (if enabled) similarity
823
813
check_only_join_nodes : false ,
824
814
// By default, there's no artificial bound on the amount of work done per phase
@@ -827,28 +817,6 @@ impl<H> ForwardPartialPathStitcher<H> {
827
817
phase_number : 1 ,
828
818
}
829
819
}
830
- }
831
-
832
- impl < H : Clone > ForwardPartialPathStitcher < H > {
833
- /// Returns an iterator of all of the (possibly incomplete) partial paths that were encountered
834
- /// during the most recent phase of the algorithm.
835
- pub fn previous_phase_partial_paths ( & self ) -> impl Iterator < Item = & PartialPath > + ' _ {
836
- self . next_iteration . 0 . iter ( )
837
- }
838
-
839
- /// Returns a slice of all of the (possibly incomplete) partial paths that were encountered
840
- /// during the most recent phase of the algorithm.
841
- pub fn previous_phase_partial_paths_slice ( & mut self ) -> & [ PartialPath ] {
842
- self . next_iteration . 0 . make_contiguous ( ) ;
843
- self . next_iteration . 0 . as_slices ( ) . 0
844
- }
845
-
846
- /// Returns a mutable slice of all of the (possibly incomplete) partial paths that were
847
- /// encountered during the most recent phase of the algorithm.
848
- pub fn previous_phase_partial_paths_slice_mut ( & mut self ) -> & mut [ PartialPath ] {
849
- self . next_iteration . 0 . make_contiguous ( ) ;
850
- self . next_iteration . 0 . as_mut_slices ( ) . 0
851
- }
852
820
853
821
/// Sets whether similar path detection should be enabled during path stitching. Paths are similar
854
822
/// if start and end node, and pre- and postconditions are the same. The presence of similar paths
@@ -878,6 +846,28 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
878
846
pub fn set_max_work_per_phase ( & mut self , max_work_per_phase : usize ) {
879
847
self . max_work_per_phase = max_work_per_phase;
880
848
}
849
+ }
850
+
851
+ impl < H : Clone > ForwardPartialPathStitcher < H > {
852
+ /// Returns an iterator of all of the (possibly incomplete) partial paths that were encountered
853
+ /// during the most recent phase of the algorithm.
854
+ pub fn previous_phase_partial_paths ( & self ) -> impl Iterator < Item = & PartialPath > + ' _ {
855
+ self . next_iteration . 0 . iter ( )
856
+ }
857
+
858
+ /// Returns a slice of all of the (possibly incomplete) partial paths that were encountered
859
+ /// during the most recent phase of the algorithm.
860
+ pub fn previous_phase_partial_paths_slice ( & mut self ) -> & [ PartialPath ] {
861
+ self . next_iteration . 0 . make_contiguous ( ) ;
862
+ self . next_iteration . 0 . as_slices ( ) . 0
863
+ }
864
+
865
+ /// Returns a mutable slice of all of the (possibly incomplete) partial paths that were
866
+ /// encountered during the most recent phase of the algorithm.
867
+ pub fn previous_phase_partial_paths_slice_mut ( & mut self ) -> & mut [ PartialPath ] {
868
+ self . next_iteration . 0 . make_contiguous ( ) ;
869
+ self . next_iteration . 0 . as_mut_slices ( ) . 0
870
+ }
881
871
882
872
/// Attempts to extend one partial path as part of the algorithm. When calling this function,
883
873
/// you are responsible for ensuring that `db` already contains all of the possible appendables
@@ -1092,7 +1082,7 @@ impl ForwardPartialPathStitcher<Edge> {
1092
1082
graph : & StackGraph ,
1093
1083
partials : & mut PartialPaths ,
1094
1084
file : Handle < File > ,
1095
- config : & StitcherConfig ,
1085
+ config : StitcherConfig ,
1096
1086
cancellation_flag : & dyn CancellationFlag ,
1097
1087
mut visit : F ,
1098
1088
) -> Result < ( ) , CancellationError >
@@ -1111,7 +1101,8 @@ impl ForwardPartialPathStitcher<Edge> {
1111
1101
. map ( |node| PartialPath :: from_node ( graph, partials, node) )
1112
1102
. collect :: < Vec < _ > > ( ) ;
1113
1103
let mut stitcher =
1114
- ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths, config) ;
1104
+ ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths) ;
1105
+ config. apply ( & mut stitcher) ;
1115
1106
stitcher. set_check_only_join_nodes ( true ) ;
1116
1107
while !stitcher. is_complete ( ) {
1117
1108
cancellation_flag. check ( "finding complete partial paths" ) ?;
@@ -1144,7 +1135,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
1144
1135
pub fn find_all_complete_partial_paths < I , F , A , Db , C , Err > (
1145
1136
candidates : & mut C ,
1146
1137
starting_nodes : I ,
1147
- config : & StitcherConfig ,
1138
+ config : StitcherConfig ,
1148
1139
cancellation_flag : & dyn CancellationFlag ,
1149
1140
mut visit : F ,
1150
1141
) -> Result < ( ) , Err >
@@ -1156,19 +1147,19 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
1156
1147
F : FnMut ( & StackGraph , & mut PartialPaths , & PartialPath ) ,
1157
1148
Err : std:: convert:: From < CancellationError > ,
1158
1149
{
1159
- let mut stitcher = {
1160
- let ( graph , partials , _ ) = candidates . get_graph_partials_and_db ( ) ;
1161
- let initial_paths = starting_nodes
1162
- . into_iter ( )
1163
- . filter ( |n| graph [ * n ] . is_reference ( ) )
1164
- . map ( |n| {
1165
- let mut p = PartialPath :: from_node ( graph , partials, n ) ;
1166
- p . eliminate_precondition_stack_variables ( partials ) ;
1167
- p
1168
- } )
1169
- . collect :: < Vec < _ > > ( ) ;
1170
- ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths, config )
1171
- } ;
1150
+ let ( graph , partials , _ ) = candidates . get_graph_partials_and_db ( ) ;
1151
+ let initial_paths = starting_nodes
1152
+ . into_iter ( )
1153
+ . filter ( |n| graph [ * n ] . is_reference ( ) )
1154
+ . map ( |n| {
1155
+ let mut p = PartialPath :: from_node ( graph , partials , n ) ;
1156
+ p . eliminate_precondition_stack_variables ( partials) ;
1157
+ p
1158
+ } )
1159
+ . collect :: < Vec < _ > > ( ) ;
1160
+ let mut stitcher =
1161
+ ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths) ;
1162
+ config . apply ( & mut stitcher ) ;
1172
1163
stitcher. set_check_only_join_nodes ( true ) ;
1173
1164
while !stitcher. is_complete ( ) {
1174
1165
cancellation_flag. check ( "finding complete partial paths" ) ?;
@@ -1186,3 +1177,25 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
1186
1177
Ok ( ( ) )
1187
1178
}
1188
1179
}
1180
+
1181
+ /// Configuration for partial path stitchers.
1182
+ #[ repr( C ) ]
1183
+ #[ derive( Clone , Copy , Debug ) ]
1184
+ pub struct StitcherConfig {
1185
+ /// Enables similar path detection during path stitching.
1186
+ pub detect_similar_paths : bool ,
1187
+ }
1188
+
1189
+ impl StitcherConfig {
1190
+ fn apply < H > ( & self , stitcher : & mut ForwardPartialPathStitcher < H > ) {
1191
+ stitcher. set_similar_path_detection ( self . detect_similar_paths ) ;
1192
+ }
1193
+ }
1194
+
1195
+ impl Default for StitcherConfig {
1196
+ fn default ( ) -> Self {
1197
+ Self {
1198
+ detect_similar_paths : true ,
1199
+ }
1200
+ }
1201
+ }
0 commit comments