Expand description
Cycle detection for the blocking dependency graph.
§Overview
Blocking dependencies form a directed graph. Cycles make items permanently stuck (each item waits on another in the loop). This module detects cycles when a new blocking edge is added and returns a warning with the cycle path.
§Design
- DFS-based: Standard depth-first search from the target of the new edge, looking for a path back to the source. This detects the cycle that the new edge closes.
- Warn, don’t block: Cycles are user errors, not system errors. The link is still added to the CRDT; the caller is responsible for surfacing the warning.
- O(V+E): Each detection check visits each node and edge at most once.
§Usage
ⓘ
use bones_core::graph::cycles::{detect_cycle_on_add, CycleWarning};
use bones_core::graph::blocking::BlockingGraph;
let graph = BlockingGraph::from_states(&states);
if let Some(warning) = detect_cycle_on_add(&graph, "bn-task1", "bn-task2") {
eprintln!("Warning: {warning}");
}Structs§
- Cycle
Warning - A warning emitted when a new blocking edge would close a cycle.
Functions§
- detect_
cycle_ on_ add - Detect whether adding a blocking edge
from → to(meaningfromis blocked byto) would create a cycle in the blocking graph. - find_
all_ cycles - Detect all cycles in the blocking graph using Tarjan-style DFS.
- has_
cycles - Check whether the blocking graph has any cycles at all.