pub struct WorkflowDag {
pub nodes: HashMap<NodeId, WorkflowNode>,
pub edges: Vec<WorkflowEdge>,
/* private fields */
}Expand description
A directed acyclic graph of WorkflowNodes connected by WorkflowEdges.
Provides cycle detection and Kahn’s-algorithm topological sort.
The topological sort result is cached after the first computation and invalidated automatically whenever the graph topology changes (node or edge mutations).
Fields§
§nodes: HashMap<NodeId, WorkflowNode>Nodes, keyed by their ID.
edges: Vec<WorkflowEdge>Edges in insertion order.
Implementations§
Source§impl WorkflowDag
impl WorkflowDag
Sourcepub fn add_node(&mut self, node: WorkflowNode) -> Result<NodeId, DagError>
pub fn add_node(&mut self, node: WorkflowNode) -> Result<NodeId, DagError>
Add a node. Returns an error if the node ID already exists.
Sourcepub fn add_edge(&mut self, edge: WorkflowEdge) -> Result<(), DagError>
pub fn add_edge(&mut self, edge: WorkflowEdge) -> Result<(), DagError>
Add an edge. Both nodes must already exist.
Sourcepub fn topological_sort(&self) -> Result<Vec<NodeId>, DagError>
pub fn topological_sort(&self) -> Result<Vec<NodeId>, DagError>
Topological sort using Kahn’s algorithm.
Returns nodes in an order where every dependency appears before its dependents. The result is cached after the first call and reused on subsequent calls until the graph topology changes.
Sourcepub fn predecessors(&self, node_id: NodeId) -> Vec<NodeId>
pub fn predecessors(&self, node_id: NodeId) -> Vec<NodeId>
Return immediate predecessors of node_id.
Sourcepub fn successors(&self, node_id: NodeId) -> Vec<NodeId>
pub fn successors(&self, node_id: NodeId) -> Vec<NodeId>
Return immediate successors of node_id.
Source§impl WorkflowDag
impl WorkflowDag
Sourcepub fn execute_with_branches(
&mut self,
branches: &HashMap<NodeId, BranchNode>,
executor: Option<&dyn Fn(&mut WorkflowNode) -> Result<(), String>>,
) -> Result<DagRunStatus, DagError>
pub fn execute_with_branches( &mut self, branches: &HashMap<NodeId, BranchNode>, executor: Option<&dyn Fn(&mut WorkflowNode) -> Result<(), String>>, ) -> Result<DagRunStatus, DagError>
Execute the DAG with branch support.
For each branch node found (identified by node IDs in branches),
only the selected successor path is activated; the other paths’
nodes are marked Skipped.
§Errors
Returns DagError if the DAG contains a cycle.
Sourcepub fn descendants(&self, node_id: NodeId) -> HashSet<NodeId>
pub fn descendants(&self, node_id: NodeId) -> HashSet<NodeId>
Return all transitive descendants of the given node.