pub struct Dag<V> { /* private fields */ }Expand description
A directed acyclic graph of V-valued nodes.
Implementations§
Source§impl<V> Dag<V>
impl<V> Dag<V>
Sourcepub fn add_node(&mut self, value: V) -> usize
pub fn add_node(&mut self, value: V) -> usize
Adds a node to the graph, returns index of the node.
Sourcepub fn add_edge(&mut self, from: usize, to: usize)
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.
Sourcepub fn node_mut(&mut self, idx: usize) -> &mut Node<V>
pub fn node_mut(&mut self, idx: usize) -> &mut Node<V>
Returns a mutable reference to the node at the given index.
Sourcepub fn topological_sort(&self) -> Vec<usize>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more