Rename WithNumEdges => NumEdges and WithStartNode => StartNode
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::{DirectedGraph, Successors, WithStartNode};
|
||||
use super::{DirectedGraph, StartNode, Successors};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use std::ops::ControlFlow;
|
||||
@@ -278,7 +278,7 @@ where
|
||||
|
||||
impl<G> TriColorDepthFirstSearch<'_, G>
|
||||
where
|
||||
G: ?Sized + DirectedGraph + Successors + WithStartNode,
|
||||
G: ?Sized + DirectedGraph + Successors + StartNode,
|
||||
{
|
||||
/// Performs a depth-first search, starting from `G::start_node()`.
|
||||
///
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -8,7 +8,7 @@ impl<'graph, G: DirectedGraph> DirectedGraph for &'graph G {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'graph, G: WithStartNode> WithStartNode for &'graph G {
|
||||
impl<'graph, G: StartNode> StartNode for &'graph G {
|
||||
fn start_node(&self) -> Self::Node {
|
||||
(**self).start_node()
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
use crate::fx::FxHashSet;
|
||||
use crate::graph::vec_graph::VecGraph;
|
||||
use crate::graph::{DirectedGraph, Successors, WithNumEdges};
|
||||
use crate::graph::{DirectedGraph, NumEdges, Successors};
|
||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||
use std::ops::Range;
|
||||
|
||||
@@ -97,7 +97,7 @@ impl<N: Idx, S: Idx + Ord> DirectedGraph for Sccs<N, S> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Idx, S: Idx + Ord> WithNumEdges for Sccs<N, S> {
|
||||
impl<N: Idx, S: Idx + Ord> NumEdges for Sccs<N, S> {
|
||||
fn num_edges(&self) -> usize {
|
||||
self.scc_data.all_successors.len()
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ impl DirectedGraph for TestGraph {
|
||||
}
|
||||
}
|
||||
|
||||
impl WithStartNode for TestGraph {
|
||||
impl StartNode for TestGraph {
|
||||
fn start_node(&self) -> usize {
|
||||
self.start_node
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::graph::{DirectedGraph, Successors, WithNumEdges};
|
||||
use crate::graph::{DirectedGraph, NumEdges, Successors};
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -86,7 +86,7 @@ impl<N: Idx> DirectedGraph for VecGraph<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Idx> WithNumEdges for VecGraph<N> {
|
||||
impl<N: Idx> NumEdges for VecGraph<N> {
|
||||
fn num_edges(&self) -> usize {
|
||||
self.edge_targets.len()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user