Struct radicle_dag::Dag
source · 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 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
.