Skip to main content

Dag

Struct Dag 

Source
pub struct Dag<V> { /* private fields */ }
Expand description

A directed acyclic graph of V-valued nodes.

Implementations§

Source§

impl<V> Dag<V>

Source

pub fn new() -> Self

Create an empty DAG.

Source

pub fn add_node(&mut self, value: V) -> usize

Adds a node to the graph, returns index of the node.

Source

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

Adds a directed edge from from to to. Panics if indices are out of bounds or would cause a self-loop. Ignores duplicate edges.

Source

pub fn node(&self, idx: usize) -> &Node<V>

Returns a reference to the node at the given index.

Source

pub fn node_mut(&mut self, idx: usize) -> &mut Node<V>

Returns a mutable reference to the node at the given index.

Source

pub fn len(&self) -> usize

Returns the number of nodes in the graph.

Source

pub fn is_empty(&self) -> bool

Returns true if the graph contains no nodes.

Source

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

Perform a topological sort. Returns a list of node indices. Panics if the graph contains a cycle.

Trait Implementations§

Source§

impl<V> Default for Dag<V>

Source§

fn default() -> Self

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

impl<V> IntoIterator for Dag<V>

Source§

type Item = Node<V>

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Node<V>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<V> Freeze for Dag<V>

§

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

§

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

§

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

§

impl<V> Unpin for Dag<V>
where V: Unpin,

§

impl<V> UnsafeUnpin for Dag<V>

§

impl<V> UnwindSafe for Dag<V>
where V: UnwindSafe,

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> Same for T

Source§

type Output = T

Should always be Self
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.