Commit 0e01108f authored by Luke Sandberg's avatar Luke Sandberg

comments

parent 0af26f38
...@@ -132,25 +132,25 @@ pub async fn map_client_references( ...@@ -132,25 +132,25 @@ pub async fn map_client_references(
return Some(Rc::from(vec![u])); return Some(Rc::from(vec![u]));
} }
// 1. Memoization check: If already computed, return cached result. // Memoization check: If already computed, return cached result.
// From any given node in a directed graph the DFS result is the same
if let Some(cached_result) = memo.get(&u) { if let Some(cached_result) = memo.get(&u) {
return cached_result.clone(); return cached_result.clone();
} }
// 2. Cycle detection: If 'u' is currently in recursion stack, it's a cycle. // Check for cycles, treat as empty since we are already visiting it, but we don't store
// For DFS post-order, we simply don't add 'u' or its descendants from this path // in the memo
// until the cycle is naturally broken or handled by memoization from another path.
if !visiting_stack.insert(u) { if !visiting_stack.insert(u) {
return None; return None;
} }
// 3. Recursively visit neighbors or consume ourselves, we don't consider client // Recursively visit neighbors
// references to be traversable.
let mut transitive_client_refs = None; let mut transitive_client_refs = None;
let mut first = None; let mut first = None;
for v in graph.neighbors(u) { for v in graph.neighbors(u) {
// This ignores back edges because we must have already visited them. // This ignores back edges because we must have already visited them and of course
// empty subgraphs as well.
if let Some(green_nodes_from_v) = dfs_collect_shallow_client_references( if let Some(green_nodes_from_v) = dfs_collect_shallow_client_references(
false, false,
v, v,
...@@ -162,6 +162,8 @@ pub async fn map_client_references( ...@@ -162,6 +162,8 @@ pub async fn map_client_references(
// Merge results from sub-paths // Merge results from sub-paths
// Save the first one on the relatively likely chance that we don't actually // Save the first one on the relatively likely chance that we don't actually
// accumulate _more_. // accumulate _more_.
// This is the most expensive part of the traversal, accumulating the ordered
// sets.
match &first { match &first {
None => { None => {
first = Some(green_nodes_from_v.clone()); first = Some(green_nodes_from_v.clone());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment