pub struct DiGraph<N: GraphNode> {
    nodes: IndexSet<Rc<N>>,
    edges: IndexMap<Rc<N>, IndexSet<Rc<N>>>,
}Expand description
A directed graph using reference-counted nodes.
Fields§
§nodes: IndexSet<Rc<N>>The set of nodes in the graph.
edges: IndexMap<Rc<N>, IndexSet<Rc<N>>>The directed edges in the graph. Each entry in the map is a node in the graph, and the set of nodes that it points to.
Implementations§
Source§impl<N: GraphNode> DiGraph<N>
 
impl<N: GraphNode> DiGraph<N>
Sourcepub fn nodes(&self) -> impl Iterator<Item = &N>
 
pub fn nodes(&self) -> impl Iterator<Item = &N>
Returns an iterator over the nodes in the graph.
Sourcepub fn remove_node(&mut self, node: &N) -> bool
 
pub fn remove_node(&mut self, node: &N) -> bool
Removes a node and all associated edges from the graph.
Sourcepub fn neighbors(&self, node: &N) -> impl Iterator<Item = &N>
 
pub fn neighbors(&self, node: &N) -> impl Iterator<Item = &N>
Returns an iterator to the immediate neighbors of a given node.
Sourcepub fn contains_node(&self, node: N) -> bool
 
pub fn contains_node(&self, node: N) -> bool
Returns true if the graph contains the given node.
Sourcepub fn post_order(&self) -> Result<IndexSet<N>, DiGraphError<N>>
 
pub fn post_order(&self) -> Result<IndexSet<N>, DiGraphError<N>>
Returns the post-order ordering of the graph. Detects if there is a cycle in the graph.
Sourcepub fn post_order_with_filter<F>(
    &self,
    filter: F,
) -> Result<IndexSet<N>, DiGraphError<N>>
 
pub fn post_order_with_filter<F>( &self, filter: F, ) -> Result<IndexSet<N>, DiGraphError<N>>
Returns the post-order ordering of the graph but only considering a subset of the nodes that satisfy the given filter.
Detects if there is a cycle in the graph.
Sourcepub fn retain_nodes(&mut self, keep: &IndexSet<N>)
 
pub fn retain_nodes(&mut self, keep: &IndexSet<N>)
Retains a subset of the nodes, and removes all edges in which the source or destination is not in the subset.
fn contains_cycle_from( &self, node: &Rc<N>, discovered: &mut IndexSet<Rc<N>>, finished: &mut IndexSet<Rc<N>>, ) -> Option<Rc<N>>
Sourcefn get_or_insert(&mut self, node: N) -> Rc<N>
 
fn get_or_insert(&mut self, node: N) -> Rc<N>
Helper: get or insert Rc
Trait Implementations§
impl<N: Eq + GraphNode> Eq for DiGraph<N>
impl<N: GraphNode> StructuralPartialEq for DiGraph<N>
Auto Trait Implementations§
impl<N> Freeze for DiGraph<N>
impl<N> RefUnwindSafe for DiGraph<N>where
    N: RefUnwindSafe,
impl<N> !Send for DiGraph<N>
impl<N> !Sync for DiGraph<N>
impl<N> Unpin for DiGraph<N>
impl<N> UnwindSafe for DiGraph<N>where
    N: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
§impl<Q, K> Equivalent<K> for Q
 
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
 
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
 
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more