[project @ 2000-11-14 10:46:39 by simonpj]
[ghc-hetmet.git] / ghc / compiler / utils / Digraph.lhs
index 0dfc585..df34dde 100644 (file)
@@ -2,7 +2,7 @@
 module Digraph(
 
        -- At present the only one with a "nice" external interface
-       stronglyConnComp, stronglyConnCompR, SCC(..),
+       stronglyConnComp, stronglyConnCompR, SCC(..), flattenSCC, flattenSCCs,
 
        Graph, Vertex, 
        graphFromEdges, buildG, transposeG, reverseE, outdegree, indegree,
@@ -56,6 +56,14 @@ import List
 data SCC vertex = AcyclicSCC vertex
                | CyclicSCC  [vertex]
 
+flattenSCCs :: [SCC a] -> [a]
+flattenSCCs = concatMap flattenSCC
+
+flattenSCC (AcyclicSCC v) = [v]
+flattenSCC (CyclicSCC vs) = vs
+\end{code}
+
+\begin{code}
 stronglyConnComp
        :: Ord key
        => [(node, key, [key])]         -- The graph; its ok for the
@@ -118,11 +126,7 @@ mapT    :: (Vertex -> a -> b) -> Table a -> Table b
 mapT f t = array (bounds t) [ (,) v (f v (t!v)) | v <- indices t ]
 
 buildG :: Bounds -> [Edge] -> Graph
-#ifdef REALLY_HASKELL_1_3
 buildG bounds edges = accumArray (flip (:)) [] bounds edges
-#else
-buildG bounds edges = accumArray (flip (:)) [] bounds [(,) k v | (k,v) <- edges]
-#endif
 
 transposeG  :: Graph -> Graph
 transposeG g = buildG (bounds g) (reverseE g)