Skip to content

Commit 4e85665

Browse files
committed
implement the graph traits for SCC
1 parent 07ee532 commit 4e85665

File tree

1 file changed

+26
-1
lines changed
  • src/librustc_data_structures/graph/scc

1 file changed

+26
-1
lines changed

src/librustc_data_structures/graph/scc/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! O(n) time.
55
66
use crate::fx::FxHashSet;
7-
use crate::graph::{DirectedGraph, WithNumNodes, WithSuccessors};
7+
use crate::graph::{DirectedGraph, WithNumNodes, WithSuccessors, GraphSuccessors};
88
use crate::indexed_vec::{Idx, IndexVec};
99
use std::ops::Range;
1010

@@ -60,6 +60,31 @@ impl<N: Idx, S: Idx> Sccs<N, S> {
6060
}
6161
}
6262

63+
impl<N: Idx, S: Idx> DirectedGraph for Sccs<N, S> {
64+
type Node = S;
65+
}
66+
67+
impl<N: Idx, S: Idx> WithNumNodes for Sccs<N, S> {
68+
fn num_nodes(&self) -> usize {
69+
self.num_sccs()
70+
}
71+
}
72+
73+
impl<N: Idx, S: Idx> GraphSuccessors<'graph> for Sccs<N, S> {
74+
type Item = S;
75+
76+
type Iter = std::iter::Cloned<std::slice::Iter<'graph, S>>;
77+
}
78+
79+
impl<N: Idx, S: Idx> WithSuccessors for Sccs<N, S> {
80+
fn successors<'graph>(
81+
&'graph self,
82+
node: S
83+
) -> <Self as GraphSuccessors<'graph>>::Iter {
84+
self.successors(node).iter().cloned()
85+
}
86+
}
87+
6388
impl<S: Idx> SccData<S> {
6489
/// Number of SCCs,
6590
fn len(&self) -> usize {

0 commit comments

Comments
 (0)