pub struct DiGraph<N: Node> {
nodes: IndexSet<N>,
edges: IndexMap<N, IndexSet<N>>,
}
Expand description
A directed graph.
Fields§
§nodes: IndexSet<N>
The set of nodes in the graph.
edges: IndexMap<N, IndexSet<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: Node> DiGraph<N>
impl<N: Node> DiGraph<N>
Sourcepub fn new(nodes: IndexSet<N>) -> Self
pub fn new(nodes: IndexSet<N>) -> Self
Initializes a new DiGraph
from a vector of source nodes.
pub fn add_node(&mut self, node: N)
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) -> Option<IndexSet<N>>
pub fn neighbors(&self, node: &N) -> Option<IndexSet<N>>
Returns the set of 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_from_entry_points<F>(
&self,
is_entry_point: F,
) -> Result<IndexSet<N>, DiGraphError<N>>
pub fn post_order_from_entry_points<F>( &self, is_entry_point: F, ) -> Result<IndexSet<N>, DiGraphError<N>>
Returns the post-order ordering of the graph but only considering a subset of the nodes as “entry points”. Meaning, nodes that are not accessible from the entry nodes are not considered in the post order.
Detects if there is a cycle in the graph.
Sourcepub fn retain_nodes(&mut self, nodes: &IndexSet<N>)
pub fn retain_nodes(&mut self, nodes: &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: N, discovered: &mut IndexSet<N>, finished: &mut IndexSet<N>, ) -> Option<N>
Trait Implementations§
impl<N: Eq + Node> Eq for DiGraph<N>
impl<N: Node> 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>where
N: Send,
impl<N> Sync for DiGraph<N>where
N: Sync,
impl<N> Unpin for DiGraph<N>where
N: Unpin,
impl<N> UnwindSafe for DiGraph<N>where
N: 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
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<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
§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