@@ -16,10 +16,14 @@ pub trait DirectedGraph {
16
16
fn num_nodes ( & self ) -> usize ;
17
17
}
18
18
19
- pub trait WithNumEdges : DirectedGraph {
19
+ pub trait NumEdges : DirectedGraph {
20
20
fn num_edges ( & self ) -> usize ;
21
21
}
22
22
23
+ pub trait StartNode : DirectedGraph {
24
+ fn start_node ( & self ) -> Self :: Node ;
25
+ }
26
+
23
27
pub trait Successors : DirectedGraph {
24
28
type Successors < ' g > : Iterator < Item = Self :: Node >
25
29
where
@@ -40,20 +44,16 @@ pub trait Predecessors: DirectedGraph {
40
44
fn predecessors ( & self , node : Self :: Node ) -> Self :: Predecessors < ' _ > ;
41
45
}
42
46
43
- pub trait WithStartNode : DirectedGraph {
44
- fn start_node ( & self ) -> Self :: Node ;
45
- }
46
-
47
- pub trait ControlFlowGraph : DirectedGraph + WithStartNode + Predecessors + Successors {
47
+ pub trait ControlFlowGraph : DirectedGraph + StartNode + Predecessors + Successors {
48
48
// convenient trait
49
49
}
50
50
51
- impl < T > ControlFlowGraph for T where T : DirectedGraph + WithStartNode + Predecessors + Successors { }
51
+ impl < T > ControlFlowGraph for T where T : DirectedGraph + StartNode + Predecessors + Successors { }
52
52
53
53
/// Returns `true` if the graph has a cycle that is reachable from the start node.
54
54
pub fn is_cyclic < G > ( graph : & G ) -> bool
55
55
where
56
- G : ?Sized + DirectedGraph + WithStartNode + Successors ,
56
+ G : ?Sized + DirectedGraph + StartNode + Successors ,
57
57
{
58
58
iterate:: TriColorDepthFirstSearch :: new ( graph)
59
59
. run_from_start ( & mut iterate:: CycleDetector )
0 commit comments