mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
implement the graph traits for SCC
This commit is contained in:
@@ -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 @@ pub fn successors(&self, scc: S) -> &[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 {
|
||||
|
||||
Reference in New Issue
Block a user