pub struct TopoGraph { /* private fields */ }Expand description
Directed graph structure for topological sorting.
Implementations§
Source§impl TopoGraph
impl TopoGraph
Sourcepub fn add_node(&mut self, id: TopoNodeId)
pub fn add_node(&mut self, id: TopoNodeId)
Add a node to the graph.
Sourcepub fn add_edge(&mut self, from: TopoNodeId, to: TopoNodeId)
pub fn add_edge(&mut self, from: TopoNodeId, to: TopoNodeId)
Add a directed edge from from to to.
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 in_degree(&self, id: TopoNodeId) -> usize
pub fn in_degree(&self, id: TopoNodeId) -> usize
Return the in-degree of a node.
Sourcepub fn out_degree(&self, id: TopoNodeId) -> usize
pub fn out_degree(&self, id: TopoNodeId) -> usize
Return the out-degree of a node.
Sourcepub fn sources(&self) -> Vec<TopoNodeId>
pub fn sources(&self) -> Vec<TopoNodeId>
Return all nodes with in-degree zero (source nodes).
Sourcepub fn sinks(&self) -> Vec<TopoNodeId>
pub fn sinks(&self) -> Vec<TopoNodeId>
Return all nodes with out-degree zero (sink nodes).
Sourcepub fn sort_kahn(&self) -> Result<Vec<TopoNodeId>, TopoError>
pub fn sort_kahn(&self) -> Result<Vec<TopoNodeId>, TopoError>
Perform topological sort using Kahn’s algorithm (BFS-based).
Returns nodes in topological order or an error if a cycle exists.
Sourcepub fn sort_dfs(&self) -> Result<Vec<TopoNodeId>, TopoError>
pub fn sort_dfs(&self) -> Result<Vec<TopoNodeId>, TopoError>
Perform topological sort using DFS-based algorithm.
Returns nodes in topological order or an error if a cycle exists.
Sourcepub fn longest_path(&self) -> Result<usize, TopoError>
pub fn longest_path(&self) -> Result<usize, TopoError>
Return the longest path length in the DAG.
Sourcepub fn node_depths(&self) -> Result<HashMap<TopoNodeId, usize>, TopoError>
pub fn node_depths(&self) -> Result<HashMap<TopoNodeId, usize>, TopoError>
Return the depth (longest path from any source) for each node.
Sourcepub fn can_reach(&self, a: TopoNodeId, b: TopoNodeId) -> bool
pub fn can_reach(&self, a: TopoNodeId, b: TopoNodeId) -> bool
Check if node a can reach node b (transitively).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TopoGraph
impl RefUnwindSafe for TopoGraph
impl Send for TopoGraph
impl Sync for TopoGraph
impl Unpin for TopoGraph
impl UnsafeUnpin for TopoGraph
impl UnwindSafe for TopoGraph
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