MCPcopy Create free account
hub / github.com/AIScientists-Dev/Flowtrace / has_cycle

Function has_cycle

crates/flowtrace-core/src/validate.rs:146–180  ·  view source on GitHub ↗
(r: &Trace)

Source from the content-addressed store, hash-verified

144}
145
146fn has_cycle(r: &Trace) -> bool {
147 use std::collections::HashSet;
148 fn dfs(
149 node: &str,
150 trace: &Trace,
151 visited: &mut HashSet<String>,
152 stack: &mut HashSet<String>,
153 ) -> bool {
154 if stack.contains(node) {
155 return true;
156 }
157 if visited.contains(node) {
158 return false;
159 }
160 visited.insert(node.to_string());
161 stack.insert(node.to_string());
162 if let Some(s) = trace.steps.get(node) {
163 for dep in &s.from_steps {
164 if dfs(dep, trace, visited, stack) {
165 return true;
166 }
167 }
168 }
169 stack.remove(node);
170 false
171 }
172 let mut visited = HashSet::new();
173 let mut stack = HashSet::new();
174 for step_id in r.steps.keys() {
175 if dfs(step_id, r, &mut visited, &mut stack) {
176 return true;
177 }
178 }
179 false
180}
181
182#[cfg(test)]
183mod tests {

Callers 1

validateFunction · 0.85

Calls 1

dfsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…