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>

source

pub fn new() -> Self

Create a new empty DAG.

source

pub fn root(key: K, value: V) -> Self

Create a DAG with a root node.

source

pub fn is_empty(&self) -> bool

Check whether there are any nodes in the graph.

source

pub fn len(&self) -> usize

Return the number of nodes in the graph.

source

pub fn node(&mut self, key: K, value: V) -> Option<Node<K, V>>

Add a node to the graph.

source

pub fn dependency(&mut self, from: K, to: K)

Add a dependency from one node to the other.

source

pub fn contains(&self, key: &K) -> bool

Check if the graph contains a node.

source

pub fn get(&self, key: &K) -> Option<&Node<K, V>>

Get a node.

source

pub fn has_dependency(&self, from: &K, to: &K) -> bool

Check whether there is a dependency between two nodes.

source

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.

source

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.

source

pub fn merge(&mut self, other: Self)

Merge a DAG into this one.

source

pub fn sorted(&self) -> VecDeque<K>

Return a topological ordering of the graph’s nodes.

source

pub fn sorted_by<F>(&self, compare: F) -> VecDeque<K>
where F: FnMut(&K, &K) -> Ordering,

Return a topological ordering of the graph’s nodes. Uses a comparison function to sort partially ordered nodes.

source

pub fn prune<F>(&mut self, roots: &[K], filter: F)
where F: for<'r> FnMut(&'r K, &'r Node<K, V>, Box<dyn Iterator<Item = (&'r K, &'r Node<K, V>)> + 'r>) -> ControlFlow<()>,

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.

source

pub fn fold<A, F>(&self, roots: &[K], acc: A, filter: F) -> A
where F: for<'r> FnMut(A, &'r K, &'r Node<K, V>) -> ControlFlow<A, 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.

source

pub fn remove(&mut self, key: &K) -> Option<Node<K, V>>

Remove a node from the graph, and all its dependents.

source§

impl<K: Ord + Copy + Display, V> Dag<K, V>

source

pub fn to_dot(&self) -> String

Return the graph in “dot” format.

Trait Implementations§

source§

impl<K: Clone, V: Clone> Clone for Dag<K, V>

source§

fn clone(&self) -> Dag<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Debug, V: Debug> Debug for Dag<K, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Default, V: Default> Default for Dag<K, V>

source§

fn default() -> Dag<K, V>

Returns the “default value” for a type. Read more
source§

impl<K: Ord + Copy + Debug, V> Index<&K> for Dag<K, V>

§

type Output = Node<K, V>

The returned type after indexing.
source§

fn index(&self, key: &K) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<K: PartialEq, V: PartialEq> PartialEq for Dag<K, V>

source§

fn eq(&self, other: &Dag<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: Eq, V: Eq> Eq for Dag<K, V>

source§

impl<K, V> StructuralPartialEq for Dag<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for Dag<K, V>

§

impl<K, V> RefUnwindSafe for Dag<K, V>

§

impl<K, V> Send for Dag<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for Dag<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for Dag<K, V>

§

impl<K, V> UnwindSafe for Dag<K, V>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.