Rename WithNumEdges => NumEdges and WithStartNode => StartNode

This commit is contained in:
Maybe Waffle
2024-04-14 15:51:29 +00:00
parent 0d5fc9bf58
commit f5144938bd
9 changed files with 21 additions and 21 deletions

View File

@@ -16,10 +16,14 @@ pub trait DirectedGraph {
fn num_nodes(&self) -> usize;
}
pub trait WithNumEdges: DirectedGraph {
pub trait NumEdges: DirectedGraph {
fn num_edges(&self) -> usize;
}
pub trait StartNode: DirectedGraph {
fn start_node(&self) -> Self::Node;
}
pub trait Successors: DirectedGraph {
type Successors<'g>: Iterator<Item = Self::Node>
where
@@ -40,20 +44,16 @@ pub trait Predecessors: DirectedGraph {
fn predecessors(&self, node: Self::Node) -> Self::Predecessors<'_>;
}
pub trait WithStartNode: DirectedGraph {
fn start_node(&self) -> Self::Node;
}
pub trait ControlFlowGraph: DirectedGraph + WithStartNode + Predecessors + Successors {
pub trait ControlFlowGraph: DirectedGraph + StartNode + Predecessors + Successors {
// convenient trait
}
impl<T> ControlFlowGraph for T where T: DirectedGraph + WithStartNode + Predecessors + Successors {}
impl<T> ControlFlowGraph for T where T: DirectedGraph + StartNode + Predecessors + Successors {}
/// Returns `true` if the graph has a cycle that is reachable from the start node.
pub fn is_cyclic<G>(graph: &G) -> bool
where
G: ?Sized + DirectedGraph + WithStartNode + Successors,
G: ?Sized + DirectedGraph + StartNode + Successors,
{
iterate::TriColorDepthFirstSearch::new(graph)
.run_from_start(&mut iterate::CycleDetector)