Skip to content

Commit 233e827

Browse files
Improve comments
1 parent dc43a64 commit 233e827

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

stack-graphs/src/stitching.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,16 @@ where
172172
//-------------------------------------------------------------------------------------------------
173173
// Candidates
174174

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.
177178
pub trait ForwardCandidates<H, A, Db, Err>
178179
where
179180
A: Appendable,
180181
Db: ToAppendable<H, A>,
181182
{
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.
183185
fn load_forward_candidates(
184186
&mut self,
185187
_path: &PartialPath,
@@ -189,13 +191,14 @@ where
189191
}
190192

191193
/// 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.
194196
fn get_forward_candidates<R>(&mut self, path: &PartialPath, result: &mut R)
195197
where
196198
R: std::iter::Extend<H>;
197199

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);
199202
}
200203

201204
//-------------------------------------------------------------------------------------------------
@@ -235,7 +238,7 @@ impl ForwardCandidates<Edge, Edge, GraphEdges, CancellationError> for GraphEdgeC
235238
}));
236239
}
237240

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) {
239242
(self.graph, self.partials, &self.edges)
240243
}
241244
}
@@ -592,7 +595,7 @@ impl ForwardCandidates<Handle<PartialPath>, PartialPath, Database, CancellationE
592595
.find_candidate_partial_paths(self.graph, self.partials, path, result);
593596
}
594597

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) {
596599
(self.graph, self.partials, self.database)
597600
}
598601
}
@@ -837,7 +840,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
837840
Db: ToAppendable<H, A>,
838841
C: ForwardCandidates<H, A, Db, Err>,
839842
{
840-
let (graph, partials, db) = candidates.get_graph_and_partials();
843+
let (graph, partials, db) = candidates.get_graph_partials_and_db();
841844
copious_debugging!(" Extend {}", partial_path.display(graph, partials));
842845

843846
// check is path is cyclic, in which case we do not extend it
@@ -873,7 +876,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
873876
self.next_iteration.0.reserve(extension_count);
874877
self.next_iteration.1.reserve(extension_count);
875878
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();
877880
let extension_path = db.get_appendable(extension);
878881
copious_debugging!(" with {}", extension_path.display(graph, partials));
879882

@@ -941,7 +944,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
941944
);
942945
let mut work_performed = 0;
943946
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();
945948
copious_debugging!(
946949
"--> Candidate partial path {}",
947950
partial_path.display(graph, partials)
@@ -1058,7 +1061,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
10581061
Err: std::convert::From<CancellationError>,
10591062
{
10601063
let mut stitcher = {
1061-
let (graph, partials, _) = candidates.get_graph_and_partials();
1064+
let (graph, partials, _) = candidates.get_graph_partials_and_db();
10621065
let initial_paths = starting_nodes
10631066
.into_iter()
10641067
.filter(|n| graph[*n].is_reference())
@@ -1076,7 +1079,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
10761079
candidates.load_forward_candidates(path, cancellation_flag)?;
10771080
}
10781081
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();
10801083
for path in stitcher.previous_phase_partial_paths() {
10811084
if path.is_complete(graph) {
10821085
visit(graph, partials, path);

stack-graphs/src/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ impl ForwardCandidates<Handle<PartialPath>, PartialPath, Database, StorageError>
736736
.find_candidate_partial_paths(&self.graph, &mut self.partials, path, result);
737737
}
738738

739-
fn get_graph_and_partials(&mut self) -> (&StackGraph, &mut PartialPaths, &Database) {
739+
fn get_graph_partials_and_db(&mut self) -> (&StackGraph, &mut PartialPaths, &Database) {
740740
(&self.graph, &mut self.partials, &self.db)
741741
}
742742
}

0 commit comments

Comments
 (0)