pub struct Dag {
pub nodes: Vec<DagNode>,
forward: Vec<Vec<usize>>,
}Expand description
Complete DAG state: nodes + reverse index.
Fields§
§nodes: Vec<DagNode>§forward: Vec<Vec<usize>>Forward adjacency: node → list of nodes that depend on it (downstream).
Implementations§
Source§impl Dag
impl Dag
Sourcepub fn new(nodes: Vec<DagNode>) -> Self
pub fn new(nodes: Vec<DagNode>) -> Self
Build a DAG from a set of nodes. Nodes must be indexed 0..n-1. Automatically builds the forward (reverse-edge) index.
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
Sourcepub fn downstream(&self, node: usize) -> &[usize]
pub fn downstream(&self, node: usize) -> &[usize]
Get direct downstream dependents of a node.
Sourcepub fn all_upstream(&self, node: usize) -> Vec<usize>
pub fn all_upstream(&self, node: usize) -> Vec<usize>
Get all transitive upstream nodes (BFS).
Sourcepub fn all_downstream(&self, node: usize) -> Vec<usize>
pub fn all_downstream(&self, node: usize) -> Vec<usize>
Get all transitive downstream nodes (BFS). This is the invalidation cascade.
Sourcepub fn topological_sort(&self) -> Option<Vec<usize>>
pub fn topological_sort(&self) -> Option<Vec<usize>>
Kahn’s algorithm. Returns None if cycle detected.
Sourcepub fn detect_cycle(&self) -> Option<Vec<usize>>
pub fn detect_cycle(&self) -> Option<Vec<usize>>
Returns the cycle path if one exists, or None.
Sourcepub fn compute_depths(&self) -> Vec<usize>
pub fn compute_depths(&self) -> Vec<usize>
Compute the depth (longest path from any root) of each node. Roots (no dependencies) have depth 0.
Sourcepub fn critical_path(&self) -> Vec<usize>
pub fn critical_path(&self) -> Vec<usize>
Find the longest path (critical path) from any root to any leaf. Returns the path as a sequence of node indices.
Sourcepub fn assign_layers(&self) -> (Vec<usize>, usize)
pub fn assign_layers(&self) -> (Vec<usize>, usize)
Assign layers using a depth-based approach for proper dependency flow. Returns (layer_assignment, max_layer). Layer 0 = leftmost/topmost (roots).
Sourcepub fn minimize_crossings(
&self,
layers: &[usize],
max_layer: usize,
) -> Vec<Vec<usize>>
pub fn minimize_crossings( &self, layers: &[usize], max_layer: usize, ) -> Vec<Vec<usize>>
Minimize edge crossings within each layer using the barycenter heuristic.
Takes layer assignments and returns an ordering of nodes within each layer.
Returns Vec<Vec
Sourcepub fn layout(&self, width: f64, height: f64) -> Vec<(f64, f64)>
pub fn layout(&self, width: f64, height: f64) -> Vec<(f64, f64)>
Full Sugiyama layout: returns (x, y) positions for each node. Coordinates are normalized to [0, 1] range.
Sourcepub fn subgraph<F>(&self, predicate: F, depth: usize) -> Vec<usize>
pub fn subgraph<F>(&self, predicate: F, depth: usize) -> Vec<usize>
Extract a subgraph containing only nodes matching a predicate, plus their transitive dependencies and dependents up to a given depth. Returns the set of included node indices.
fn expand_direction( &self, start: usize, max_depth: usize, upstream: bool, included: &mut [bool], )
Sourcepub fn impact_analysis(&self, node: usize) -> ImpactResult
pub fn impact_analysis(&self, node: usize) -> ImpactResult
Simulate invalidating a node: returns (cascade_count, affected_by_type). affected_by_type[i] = count of affected nodes of type i (indexed by NodeType::layer_order).
pub fn orphans(&self) -> Vec<usize>
Sourcepub fn validate(&self) -> Vec<String>
pub fn validate(&self) -> Vec<String>
Validate the DAG state. Returns a list of issues (empty = valid). Issues starting with “ERROR:” are critical; “WARN:” are advisory.
Sourcepub fn stale_nodes(&self) -> Vec<usize>
pub fn stale_nodes(&self) -> Vec<usize>
Get stale nodes sorted by dependency depth (shallowest first).
Sourcepub fn plannable_tasks(&self) -> Vec<usize>
pub fn plannable_tasks(&self) -> Vec<usize>
Get task nodes that are ready to work on:
- Type is Task
- Status is Pending
- All dependencies are Valid
Sourcepub fn blocked_tasks(&self) -> Vec<usize>
pub fn blocked_tasks(&self) -> Vec<usize>
Get task nodes that are blocked:
- Type is Task
- Status is Pending
- At least one dependency is not Valid
Sourcepub fn active_tasks(&self) -> Vec<usize>
pub fn active_tasks(&self) -> Vec<usize>
Get active (in-progress) task nodes.
Sourcepub fn parallel_groups(&self) -> Vec<Vec<usize>>
pub fn parallel_groups(&self) -> Vec<Vec<usize>>
Find groups of plannable tasks that can be executed in parallel (no mutual transitive dependencies).
Sourcepub fn count_crossings(&self, positions: &[(f64, f64)]) -> usize
pub fn count_crossings(&self, positions: &[(f64, f64)]) -> usize
Count the number of edge crossings given a set of node positions. Lower is better for readability.
Sourcepub fn find_paths(
&self,
source: usize,
target: usize,
max_paths: usize,
) -> Vec<Vec<usize>>
pub fn find_paths( &self, source: usize, target: usize, max_paths: usize, ) -> Vec<Vec<usize>>
Find all paths from source to target. Returns paths sorted by length.
Limits to max_paths to prevent combinatorial explosion.