@@ -795,13 +795,6 @@ impl<'a> Display for DisplaySymbolStackKey<'a> {
795795//-------------------------------------------------------------------------------------------------
796796// Stitching partial paths together
797797
798- /// Configuration for partial path stitchers.
799- #[ derive( Clone , Debug , Default ) ]
800- pub struct StitcherConfig {
801- /// Enables similar path detection during path stitching.
802- pub detect_similar_paths : bool ,
803- }
804-
805798/// Implements a phased forward partial path stitching algorithm.
806799///
807800/// Our overall goal is to start with a set of _seed_ partial paths, and to repeatedly extend each
@@ -858,7 +851,6 @@ impl<H> ForwardPartialPathStitcher<H> {
858851 _graph : & StackGraph ,
859852 _partials : & mut PartialPaths ,
860853 initial_partial_paths : I ,
861- config : & StitcherConfig ,
862854 ) -> Self
863855 where
864856 I : IntoIterator < Item = PartialPath > ,
@@ -871,16 +863,14 @@ impl<H> ForwardPartialPathStitcher<H> {
871863 ( p, c, false )
872864 } )
873865 . multiunzip ( ) ;
874- let similar_path_detector =
875- Some ( SimilarPathDetector :: new ( ) ) . filter ( |_| config. detect_similar_paths ) ;
876- ForwardPartialPathStitcher {
866+ Self {
877867 candidates : Vec :: new ( ) ,
878868 extensions : Vec :: new ( ) ,
879869 queue : VecDeque :: new ( ) ,
880870 initial_paths : next_iteration. 0 . len ( ) ,
881871 next_iteration,
882872 appended_paths,
883- similar_path_detector,
873+ similar_path_detector : Some ( SimilarPathDetector :: new ( ) ) ,
884874 // By default, all nodes are checked for cycles and (if enabled) similarity
885875 check_only_join_nodes : false ,
886876 // By default, there's no artificial bound on the amount of work done per phase
@@ -889,28 +879,6 @@ impl<H> ForwardPartialPathStitcher<H> {
889879 phase_number : 1 ,
890880 }
891881 }
892- }
893-
894- impl < H : Clone > ForwardPartialPathStitcher < H > {
895- /// Returns an iterator of all of the (possibly incomplete) partial paths that were encountered
896- /// during the most recent phase of the algorithm.
897- pub fn previous_phase_partial_paths ( & self ) -> impl Iterator < Item = & PartialPath > + ' _ {
898- self . next_iteration . 0 . iter ( )
899- }
900-
901- /// Returns a slice of all of the (possibly incomplete) partial paths that were encountered
902- /// during the most recent phase of the algorithm.
903- pub fn previous_phase_partial_paths_slice ( & mut self ) -> & [ PartialPath ] {
904- self . next_iteration . 0 . make_contiguous ( ) ;
905- self . next_iteration . 0 . as_slices ( ) . 0
906- }
907-
908- /// Returns a mutable slice of all of the (possibly incomplete) partial paths that were
909- /// encountered during the most recent phase of the algorithm.
910- pub fn previous_phase_partial_paths_slice_mut ( & mut self ) -> & mut [ PartialPath ] {
911- self . next_iteration . 0 . make_contiguous ( ) ;
912- self . next_iteration . 0 . as_mut_slices ( ) . 0
913- }
914882
915883 /// Sets whether similar path detection should be enabled during path stitching. Paths are similar
916884 /// if start and end node, and pre- and postconditions are the same. The presence of similar paths
@@ -940,6 +908,28 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
940908 pub fn set_max_work_per_phase ( & mut self , max_work_per_phase : usize ) {
941909 self . max_work_per_phase = max_work_per_phase;
942910 }
911+ }
912+
913+ impl < H : Clone > ForwardPartialPathStitcher < H > {
914+ /// Returns an iterator of all of the (possibly incomplete) partial paths that were encountered
915+ /// during the most recent phase of the algorithm.
916+ pub fn previous_phase_partial_paths ( & self ) -> impl Iterator < Item = & PartialPath > + ' _ {
917+ self . next_iteration . 0 . iter ( )
918+ }
919+
920+ /// Returns a slice of all of the (possibly incomplete) partial paths that were encountered
921+ /// during the most recent phase of the algorithm.
922+ pub fn previous_phase_partial_paths_slice ( & mut self ) -> & [ PartialPath ] {
923+ self . next_iteration . 0 . make_contiguous ( ) ;
924+ self . next_iteration . 0 . as_slices ( ) . 0
925+ }
926+
927+ /// Returns a mutable slice of all of the (possibly incomplete) partial paths that were
928+ /// encountered during the most recent phase of the algorithm.
929+ pub fn previous_phase_partial_paths_slice_mut ( & mut self ) -> & mut [ PartialPath ] {
930+ self . next_iteration . 0 . make_contiguous ( ) ;
931+ self . next_iteration . 0 . as_mut_slices ( ) . 0
932+ }
943933
944934 /// Attempts to extend one partial path as part of the algorithm. When calling this function,
945935 /// you are responsible for ensuring that `db` already contains all of the possible appendables
@@ -1155,7 +1145,7 @@ impl ForwardPartialPathStitcher<Edge> {
11551145 graph : & StackGraph ,
11561146 partials : & mut PartialPaths ,
11571147 file : Handle < File > ,
1158- config : & StitcherConfig ,
1148+ config : StitcherConfig ,
11591149 cancellation_flag : & dyn CancellationFlag ,
11601150 mut visit : F ,
11611151 ) -> Result < ( ) , CancellationError >
@@ -1174,7 +1164,8 @@ impl ForwardPartialPathStitcher<Edge> {
11741164 . map ( |node| PartialPath :: from_node ( graph, partials, node) )
11751165 . collect :: < Vec < _ > > ( ) ;
11761166 let mut stitcher =
1177- ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths, config) ;
1167+ ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths) ;
1168+ config. apply ( & mut stitcher) ;
11781169 stitcher. set_check_only_join_nodes ( true ) ;
11791170 while !stitcher. is_complete ( ) {
11801171 cancellation_flag. check ( "finding complete partial paths" ) ?;
@@ -1207,7 +1198,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
12071198 pub fn find_all_complete_partial_paths < I , F , A , Db , C , Err > (
12081199 candidates : & mut C ,
12091200 starting_nodes : I ,
1210- config : & StitcherConfig ,
1201+ config : StitcherConfig ,
12111202 cancellation_flag : & dyn CancellationFlag ,
12121203 mut visit : F ,
12131204 ) -> Result < ( ) , Err >
@@ -1219,19 +1210,19 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
12191210 F : FnMut ( & StackGraph , & mut PartialPaths , & PartialPath ) ,
12201211 Err : std:: convert:: From < CancellationError > ,
12211212 {
1222- let mut stitcher = {
1223- let ( graph , partials , _ ) = candidates . get_graph_partials_and_db ( ) ;
1224- let initial_paths = starting_nodes
1225- . into_iter ( )
1226- . filter ( |n| graph [ * n ] . is_reference ( ) )
1227- . map ( |n| {
1228- let mut p = PartialPath :: from_node ( graph , partials, n ) ;
1229- p . eliminate_precondition_stack_variables ( partials ) ;
1230- p
1231- } )
1232- . collect :: < Vec < _ > > ( ) ;
1233- ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths, config )
1234- } ;
1213+ let ( graph , partials , _ ) = candidates . get_graph_partials_and_db ( ) ;
1214+ let initial_paths = starting_nodes
1215+ . into_iter ( )
1216+ . filter ( |n| graph [ * n ] . is_reference ( ) )
1217+ . map ( |n| {
1218+ let mut p = PartialPath :: from_node ( graph , partials , n ) ;
1219+ p . eliminate_precondition_stack_variables ( partials) ;
1220+ p
1221+ } )
1222+ . collect :: < Vec < _ > > ( ) ;
1223+ let mut stitcher =
1224+ ForwardPartialPathStitcher :: from_partial_paths ( graph, partials, initial_paths) ;
1225+ config . apply ( & mut stitcher ) ;
12351226 stitcher. set_check_only_join_nodes ( true ) ;
12361227 while !stitcher. is_complete ( ) {
12371228 cancellation_flag. check ( "finding complete partial paths" ) ?;
@@ -1249,3 +1240,25 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
12491240 Ok ( ( ) )
12501241 }
12511242}
1243+
1244+ /// Configuration for partial path stitchers.
1245+ #[ repr( C ) ]
1246+ #[ derive( Clone , Copy , Debug ) ]
1247+ pub struct StitcherConfig {
1248+ /// Enables similar path detection during path stitching.
1249+ pub detect_similar_paths : bool ,
1250+ }
1251+
1252+ impl StitcherConfig {
1253+ fn apply < H > ( & self , stitcher : & mut ForwardPartialPathStitcher < H > ) {
1254+ stitcher. set_similar_path_detection ( self . detect_similar_paths ) ;
1255+ }
1256+ }
1257+
1258+ impl Default for StitcherConfig {
1259+ fn default ( ) -> Self {
1260+ Self {
1261+ detect_similar_paths : true ,
1262+ }
1263+ }
1264+ }
0 commit comments