diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2019-06-11 08:48:40 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2019-07-02 12:15:20 -0400 |
| commit | 4e85665e08059a3cd96600b7972f7dcd1f62b871 (patch) | |
| tree | 81179da03a28a52f227f1e1ecba2d3c4a7d3f726 /src/librustc_data_structures | |
| parent | 07ee532031b4c9306e5db565c88bec3a0bc7308e (diff) | |
| download | rust-4e85665e08059a3cd96600b7972f7dcd1f62b871.tar.gz rust-4e85665e08059a3cd96600b7972f7dcd1f62b871.zip | |
implement the graph traits for SCC
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/graph/scc/mod.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/librustc_data_structures/graph/scc/mod.rs b/src/librustc_data_structures/graph/scc/mod.rs index 24c5448639e..7d29bd63707 100644 --- a/src/librustc_data_structures/graph/scc/mod.rs +++ b/src/librustc_data_structures/graph/scc/mod.rs @@ -4,7 +4,7 @@ //! O(n) time. use crate::fx::FxHashSet; -use crate::graph::{DirectedGraph, WithNumNodes, WithSuccessors}; +use crate::graph::{DirectedGraph, WithNumNodes, WithSuccessors, GraphSuccessors}; use crate::indexed_vec::{Idx, IndexVec}; use std::ops::Range; @@ -60,6 +60,31 @@ impl<N: Idx, S: Idx> Sccs<N, S> { } } +impl<N: Idx, S: Idx> DirectedGraph for Sccs<N, S> { + type Node = S; +} + +impl<N: Idx, S: Idx> WithNumNodes for Sccs<N, S> { + fn num_nodes(&self) -> usize { + self.num_sccs() + } +} + +impl<N: Idx, S: Idx> GraphSuccessors<'graph> for Sccs<N, S> { + type Item = S; + + type Iter = std::iter::Cloned<std::slice::Iter<'graph, S>>; +} + +impl<N: Idx, S: Idx> WithSuccessors for Sccs<N, S> { + fn successors<'graph>( + &'graph self, + node: S + ) -> <Self as GraphSuccessors<'graph>>::Iter { + self.successors(node).iter().cloned() + } +} + impl<S: Idx> SccData<S> { /// Number of SCCs, fn len(&self) -> usize { |
