@@ -172,14 +172,16 @@ where
172
172
//-------------------------------------------------------------------------------------------------
173
173
// Candidates
174
174
175
- /// A trait to support finding candidates for partial path extension. Requires an accompanying
176
- /// [`ToAppendable`] implementation to convert the candidate handles into [`Appendable`]s.
175
+ /// A trait to support finding candidates for partial path extension. The candidates are represented
176
+ /// by handles `H`, which are mapped to appendables `A` using the database `Db`. Loading errors are
177
+ /// reported as values of the `Err` type.
177
178
pub trait ForwardCandidates < H , A , Db , Err >
178
179
where
179
180
A : Appendable ,
180
181
Db : ToAppendable < H , A > ,
181
182
{
182
- /// Load possible forward candidates for the given partial path.
183
+ /// Load possible forward candidates for the given partial path into this candidates instance.
184
+ /// Must be called before [`get_forward_candidates`] to allow lazy-loading implementations.
183
185
fn load_forward_candidates (
184
186
& mut self ,
185
187
_path : & PartialPath ,
@@ -189,13 +191,14 @@ where
189
191
}
190
192
191
193
/// Get forward candidates for extending the given partial path and add them to the provided
192
- /// result instance. If the trait implementation loads data lazily, this only considers already
193
- /// loaded data.
194
+ /// result instance. If this instance loads data lazily, this only considers previously loaded
195
+ /// data.
194
196
fn get_forward_candidates < R > ( & mut self , path : & PartialPath , result : & mut R )
195
197
where
196
198
R : std:: iter:: Extend < H > ;
197
199
198
- fn get_graph_and_partials ( & mut self ) -> ( & StackGraph , & mut PartialPaths , & Db ) ;
200
+ /// Get the graph, partial path arena, and database backing this candidates instance.
201
+ fn get_graph_partials_and_db ( & mut self ) -> ( & StackGraph , & mut PartialPaths , & Db ) ;
199
202
}
200
203
201
204
//-------------------------------------------------------------------------------------------------
@@ -235,7 +238,7 @@ impl ForwardCandidates<Edge, Edge, GraphEdges, CancellationError> for GraphEdgeC
235
238
} ) ) ;
236
239
}
237
240
238
- fn get_graph_and_partials ( & mut self ) -> ( & StackGraph , & mut PartialPaths , & GraphEdges ) {
241
+ fn get_graph_partials_and_db ( & mut self ) -> ( & StackGraph , & mut PartialPaths , & GraphEdges ) {
239
242
( self . graph , self . partials , & self . edges )
240
243
}
241
244
}
@@ -592,7 +595,7 @@ impl ForwardCandidates<Handle<PartialPath>, PartialPath, Database, CancellationE
592
595
. find_candidate_partial_paths ( self . graph , self . partials , path, result) ;
593
596
}
594
597
595
- fn get_graph_and_partials ( & mut self ) -> ( & StackGraph , & mut PartialPaths , & Database ) {
598
+ fn get_graph_partials_and_db ( & mut self ) -> ( & StackGraph , & mut PartialPaths , & Database ) {
596
599
( self . graph , self . partials , self . database )
597
600
}
598
601
}
@@ -837,7 +840,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
837
840
Db : ToAppendable < H , A > ,
838
841
C : ForwardCandidates < H , A , Db , Err > ,
839
842
{
840
- let ( graph, partials, db) = candidates. get_graph_and_partials ( ) ;
843
+ let ( graph, partials, db) = candidates. get_graph_partials_and_db ( ) ;
841
844
copious_debugging ! ( " Extend {}" , partial_path. display( graph, partials) ) ;
842
845
843
846
// check is path is cyclic, in which case we do not extend it
@@ -873,7 +876,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
873
876
self . next_iteration . 0 . reserve ( extension_count) ;
874
877
self . next_iteration . 1 . reserve ( extension_count) ;
875
878
for extension in & self . candidates {
876
- let ( graph, partials, db) = candidates. get_graph_and_partials ( ) ;
879
+ let ( graph, partials, db) = candidates. get_graph_partials_and_db ( ) ;
877
880
let extension_path = db. get_appendable ( extension) ;
878
881
copious_debugging ! ( " with {}" , extension_path. display( graph, partials) ) ;
879
882
@@ -941,7 +944,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
941
944
) ;
942
945
let mut work_performed = 0 ;
943
946
while let Some ( ( partial_path, cycle_detector) ) = self . queue . pop_front ( ) {
944
- let ( graph, partials, _) = candidates. get_graph_and_partials ( ) ;
947
+ let ( graph, partials, _) = candidates. get_graph_partials_and_db ( ) ;
945
948
copious_debugging ! (
946
949
"--> Candidate partial path {}" ,
947
950
partial_path. display( graph, partials)
@@ -1058,7 +1061,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
1058
1061
Err : std:: convert:: From < CancellationError > ,
1059
1062
{
1060
1063
let mut stitcher = {
1061
- let ( graph, partials, _) = candidates. get_graph_and_partials ( ) ;
1064
+ let ( graph, partials, _) = candidates. get_graph_partials_and_db ( ) ;
1062
1065
let initial_paths = starting_nodes
1063
1066
. into_iter ( )
1064
1067
. filter ( |n| graph[ * n] . is_reference ( ) )
@@ -1076,7 +1079,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
1076
1079
candidates. load_forward_candidates ( path, cancellation_flag) ?;
1077
1080
}
1078
1081
stitcher. process_next_phase ( candidates, |_, _, _| true ) ;
1079
- let ( graph, partials, _) = candidates. get_graph_and_partials ( ) ;
1082
+ let ( graph, partials, _) = candidates. get_graph_partials_and_db ( ) ;
1080
1083
for path in stitcher. previous_phase_partial_paths ( ) {
1081
1084
if path. is_complete ( graph) {
1082
1085
visit ( graph, partials, path) ;
0 commit comments