pub struct CycleGraph { /* private fields */ }Expand description
Directed graph for cycle detection.
Implementations§
Source§impl CycleGraph
impl CycleGraph
Sourcepub fn add_node(&mut self, id: CycleNodeId)
pub fn add_node(&mut self, id: CycleNodeId)
Add a node to the graph.
Sourcepub fn add_edge(&mut self, from: CycleNodeId, to: CycleNodeId)
pub fn add_edge(&mut self, from: CycleNodeId, to: CycleNodeId)
Add a directed edge from from to to.
Sourcepub fn remove_edge(&mut self, from: CycleNodeId, to: CycleNodeId) -> bool
pub fn remove_edge(&mut self, from: CycleNodeId, to: CycleNodeId) -> bool
Remove a directed edge.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Return the number of nodes.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Return the number of edges.
Sourcepub fn detect_all_cycles(&self) -> CycleDetectionResult
pub fn detect_all_cycles(&self) -> CycleDetectionResult
Detect all cycles in the graph using DFS.
Sourcepub fn would_create_cycle(&self, from: CycleNodeId, to: CycleNodeId) -> bool
pub fn would_create_cycle(&self, from: CycleNodeId, to: CycleNodeId) -> bool
Check if adding an edge from from to to would create a cycle.
This performs a BFS from to to see if it can reach from.
Sourcepub fn try_add_edge(&mut self, from: CycleNodeId, to: CycleNodeId) -> bool
pub fn try_add_edge(&mut self, from: CycleNodeId, to: CycleNodeId) -> bool
Add an edge only if it would not create a cycle. Returns true if the edge was added, false if it would create a cycle.
Sourcepub fn cyclic_nodes(&self) -> HashSet<CycleNodeId>
pub fn cyclic_nodes(&self) -> HashSet<CycleNodeId>
Return all nodes that are part of at least one cycle.
Sourcepub fn is_in_cycle(&self, id: CycleNodeId) -> bool
pub fn is_in_cycle(&self, id: CycleNodeId) -> bool
Check if a specific node is part of any cycle.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CycleGraph
impl RefUnwindSafe for CycleGraph
impl Send for CycleGraph
impl Sync for CycleGraph
impl Unpin for CycleGraph
impl UnsafeUnpin for CycleGraph
impl UnwindSafe for CycleGraph
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
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>
Converts
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>
Converts
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