From 4e85665e08059a3cd96600b7972f7dcd1f62b871 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 11 Jun 2019 08:48:40 -0400 Subject: [PATCH] implement the graph traits for SCC --- src/librustc_data_structures/graph/scc/mod.rs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/librustc_data_structures/graph/scc/mod.rs b/src/librustc_data_structures/graph/scc/mod.rs index 24c5448639e7..7d29bd63707a 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 Sccs { } } +impl DirectedGraph for Sccs { + type Node = S; +} + +impl WithNumNodes for Sccs { + fn num_nodes(&self) -> usize { + self.num_sccs() + } +} + +impl GraphSuccessors<'graph> for Sccs { + type Item = S; + + type Iter = std::iter::Cloned>; +} + +impl WithSuccessors for Sccs { + fn successors<'graph>( + &'graph self, + node: S + ) -> >::Iter { + self.successors(node).iter().cloned() + } +} + impl SccData { /// Number of SCCs, fn len(&self) -> usize {