Struct zepter::dag::Dag

source ·
pub struct Dag<T: Ord> {
    pub edges: BTreeMap<T, BTreeSet<T>>,
}
Expand description

Represents Directed Acyclic Graph through its edge relation.

A “node” in that sense is anything on the left- or right-hand side of this relation.

Fields§

§edges: BTreeMap<T, BTreeSet<T>>

Dependant -> Dependency eg: Polkadot -> Substrate or Me -> Rust

Implementations§

source§

impl<T> Dag<T>
where T: Ord + PartialEq + Clone,

source

pub fn new() -> Self

Create a new empty Dag.

source

pub fn add_edge(&mut self, from: T, to: T)

Connect two nodes.

source

pub fn add_node(&mut self, node: T)

Add a node to the Dag without any edges.

source

pub fn degree(&self, node: &T) -> usize

source

pub fn adjacent(&self, from: &T, to: &T) -> bool

Whether from is directly adjacent to to.

Directly means with via an edge.

source

pub fn reachable(&self, from: &T, to: &T) -> bool

Whether from is reachable to to via.

source

pub fn lhs_contains(&self, from: &T) -> bool

Whether from appears on the lhs of the edge relation.

Aka: Whether self has any dependencies nodes.

source

pub fn rhs_contains(&self, to: &T) -> bool

Whether to appears on the rhs of the edge relation.

Aka: Whether any other node depends on self.

source

pub fn dag_of(&self, from: T) -> Self

The Dag only containing the node from and its direct dependencies.

This can be inflated back to the original Dag by calling from.into_transitive_hull_in(self).

source

pub fn sub(&self, pred: impl Fn(&T) -> bool) -> Self

source

pub fn lhs_node(&self, from: &T) -> Option<&T>

Get get a ref to the a LHS node.

source

pub fn lhs_nodes(&self) -> impl Iterator<Item = &T>

source

pub fn rhs_nodes(&self) -> impl Iterator<Item = &T>

source

pub fn inverse_lookup<'a>(&'a self, to: &'a T) -> impl Iterator<Item = &'a T>

source

pub fn transitive_hull(&mut self)

Calculate the transitive hull of self.

source

pub fn transitive_hull_in(&mut self, topology: &Self)

Calculate the transitive hull of self while using the connectivity of topology.

source

pub fn into_transitive_hull(self) -> Self

Consume self and return the transitive hull.

source

pub fn into_transitive_hull_in(self, topology: &Self) -> Self

Consume self and return the transitive hull while using the connectivity of topology.

source

pub fn any_path<'a>(&'a self, from: &'a T, to: &T) -> Option<Path<'a, T>>

Find any path from from to to.

Note that 1) the shortest path does not necessarily exist and 2) this function does not give any guarantee about the returned path.

This returns Some if (and only if) to is reachable from from.

source

pub fn reachable_predicate<'a>( &'a self, from: &'a T, pred: impl Fn(&T) -> bool ) -> Option<Path<'a, T>>

Check if any node which fulfills pred can be reached from from and return the first path.

source

pub fn num_edges(&self) -> usize

The number of edges in the graph.

source

pub fn num_nodes(&self) -> usize

The number of nodes in the graph.

source

pub fn lhs_iter(&self) -> impl Iterator<Item = &T>

source

pub fn rhs_iter(&self) -> impl Iterator<Item = &T>

source

pub fn node_iter(&self) -> impl Iterator<Item = &T>

Iterate though all LHS and RHS nodes.

Trait Implementations§

source§

impl<T: Clone + Ord> Clone for Dag<T>

source§

fn clone(&self) -> Dag<T>

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<T: Ord> Default for Dag<T>

source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for Dag<T>
where T: Deserialize<'de> + Ord,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T> Display for Dag<T>
where T: Display + Ord,

source§

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

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

impl<T> Serialize for Dag<T>
where T: Serialize + Ord,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Dag<T>

§

impl<T> RefUnwindSafe for Dag<T>
where T: RefUnwindSafe,

§

impl<T> Send for Dag<T>
where T: Send,

§

impl<T> Sync for Dag<T>
where T: Sync,

§

impl<T> Unpin for Dag<T>

§

impl<T> UnwindSafe for Dag<T>
where T: RefUnwindSafe,

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,