MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / walk_backward

Method walk_backward

atomic-core/src/change/provenance_graph/mod.rs:430–451  ·  view source on GitHub ↗

Walk backward from a node through its causal chain. Returns node IDs in reverse-causal order: the target node first, then its causes, then their causes, etc. Useful for answering "why did this change happen?" Stops at the graph boundary (goal nodes or nodes with no incoming edges). Avoids cycles (though the graph should be acyclic by construction).

(&self, start_node_id: &str)

Source from the content-addressed store, hash-verified

428 /// Stops at the graph boundary (goal nodes or nodes with no incoming edges).
429 /// Avoids cycles (though the graph should be acyclic by construction).
430 pub fn walk_backward(&self, start_node_id: &str) -> Vec<String> {
431 let mut result = Vec::new();
432 let mut visited = std::collections::HashSet::new();
433 let mut queue = std::collections::VecDeque::new();
434
435 queue.push_back(start_node_id.to_string());
436 visited.insert(start_node_id.to_string());
437
438 while let Some(node_id) = queue.pop_front() {
439 result.push(node_id.clone());
440
441 // Find all edges pointing TO this node (its causes)
442 for edge in &self.edges {
443 if edge.to == node_id && !visited.contains(&edge.from) {
444 visited.insert(edge.from.clone());
445 queue.push_back(edge.from.clone());
446 }
447 }
448 }
449
450 result
451 }
452}
453
454impl fmt::Display for ProvenanceGraph {

Calls 4

insertMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
containsMethod · 0.45