pub struct Dag<K, V> { /* private fields */ }
Expand description
A directed acyclic graph.
Implementations§
Source§impl<K: Ord + Copy, V> Dag<K, V>
impl<K: Ord + Copy, V> Dag<K, V>
Sourcepub fn dependency(&mut self, from: K, to: K)
pub fn dependency(&mut self, from: K, to: K)
Add a dependency from one node to the other.
Sourcepub fn has_dependency(&self, from: &K, to: &K) -> bool
pub fn has_dependency(&self, from: &K, to: &K) -> bool
Check whether there is a dependency between two nodes.
Sourcepub fn roots(&self) -> impl Iterator<Item = (&K, &Node<K, V>)> + '_
pub fn roots(&self) -> impl Iterator<Item = (&K, &Node<K, V>)> + '_
Get the graph’s root nodes, ie. nodes which don’t depend on other nodes.
Sourcepub fn tips(&self) -> impl Iterator<Item = (&K, &Node<K, V>)> + '_
pub fn tips(&self) -> impl Iterator<Item = (&K, &Node<K, V>)> + '_
Get the graph’s tip nodes, ie. nodes which aren’t depended on by other nodes.
Sourcepub fn sorted_by<F>(&self, compare: F) -> VecDeque<K>
pub fn sorted_by<F>(&self, compare: F) -> VecDeque<K>
Return a topological ordering of the graph’s nodes. Uses a comparison function to sort partially ordered nodes.
Sourcepub fn prune<F>(&mut self, roots: &[K], filter: F)
pub fn prune<F>(&mut self, roots: &[K], filter: F)
Fold over the graph in topological order, pruning branches along the way. This is a depth-first traversal.
To continue traversing a branch, return ControlFlow::Continue
from the
filter function. To stop traversal of a branch and prune it,
return ControlFlow::Break
.
Sourcepub fn prune_by<F, P>(&mut self, roots: &[K], filter: F, ordering: P)
pub fn prune_by<F, P>(&mut self, roots: &[K], filter: F, ordering: P)
Fold over the graph in the order provided by order
, pruning branches
along the way.
This is a depth-first traversal.
To continue traversing a branch, return ControlFlow::Continue
from the
filter function. To stop traversal of a branch and prune it,
return ControlFlow::Break
.
Sourcepub fn fold<A, F>(&self, roots: &[K], acc: A, filter: F) -> A
pub fn fold<A, F>(&self, roots: &[K], acc: A, filter: F) -> A
Fold over the graph in topological order, skipping certain branches. This is a depth-first traversal.
To continue traversing a branch, return ControlFlow::Continue
from the
filter function. To stop traversal of a branch, return ControlFlow::Break
.