Dag

Struct Dag 

Source
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

Source

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.

Source

pub fn node_count(&self) -> usize

Source

pub fn edge_count(&self) -> usize

Source

pub fn upstream(&self, node: usize) -> &[usize]

Get direct upstream dependencies of a node.

Source

pub fn downstream(&self, node: usize) -> &[usize]

Get direct downstream dependents of a node.

Source

pub fn all_upstream(&self, node: usize) -> Vec<usize>

Get all transitive upstream nodes (BFS).

Source

pub fn all_downstream(&self, node: usize) -> Vec<usize>

Get all transitive downstream nodes (BFS). This is the invalidation cascade.

Source

pub fn topological_sort(&self) -> Option<Vec<usize>>

Kahn’s algorithm. Returns None if cycle detected.

Source

pub fn detect_cycle(&self) -> Option<Vec<usize>>

Returns the cycle path if one exists, or None.

Source

pub fn compute_depths(&self) -> Vec<usize>

Compute the depth (longest path from any root) of each node. Roots (no dependencies) have depth 0.

Source

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.

Source

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).

Source

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> where result[layer] = ordered node indices in that layer.

Source

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.

Source

pub fn subgraph<F>(&self, predicate: F, depth: usize) -> Vec<usize>
where F: Fn(&DagNode) -> bool,

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.

Source

fn expand_direction( &self, start: usize, max_depth: usize, upstream: bool, included: &mut [bool], )

Source

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).

Source

pub fn orphans(&self) -> Vec<usize>

Source

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.

Source

pub fn stale_nodes(&self) -> Vec<usize>

Get stale nodes sorted by dependency depth (shallowest first).

Source

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
Source

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
Source

pub fn active_tasks(&self) -> Vec<usize>

Get active (in-progress) task nodes.

Source

pub fn parallel_groups(&self) -> Vec<Vec<usize>>

Find groups of plannable tasks that can be executed in parallel (no mutual transitive dependencies).

Source

pub fn summarize(&self) -> String

Summarize the DAG state as a human-readable string.

Source

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.

Source

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.

Source

fn dfs_paths( &self, current: usize, target: usize, path: &mut Vec<usize>, result: &mut Vec<Vec<usize>>, max_paths: usize, )

Auto Trait Implementations§

§

impl Freeze for Dag

§

impl RefUnwindSafe for Dag

§

impl Send for Dag

§

impl Sync for Dag

§

impl Unpin for Dag

§

impl UnwindSafe for Dag

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.