X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FDigraph.lhs;h=f80b33f870517806b8e8a48714b91c25d803a470;hb=47adb8b6c491df7e51fd34e6bb45dfe3d6fe681a;hp=cde008ad9a2307490c26ac88c3f47b1c34b8af18;hpb=9ec880fcb29ff038bcc72d78bbe2fd6933566047;p=ghc-hetmet.git diff --git a/compiler/utils/Digraph.lhs b/compiler/utils/Digraph.lhs index cde008a..f80b33f 100644 --- a/compiler/utils/Digraph.lhs +++ b/compiler/utils/Digraph.lhs @@ -3,6 +3,13 @@ % \begin{code} +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module Digraph( -- At present the only one with a "nice" external interface @@ -76,6 +83,16 @@ instance Outputable a => Outputable (SCC a) where ppr (CyclicSCC vs) = text "REC" $$ (nest 3 (vcat (map ppr vs))) \end{code} +Note [Nodes, keys, vertices] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * A 'node' is a big blob of client-stuff + + * Each 'node' has a unique (client) 'key', but the latter + is in Ord and has fast comparison + + * Digraph then maps each 'key' to a Vertex (Int) which is + arranged densely in 0.n + \begin{code} stronglyConnComp :: Ord key @@ -323,17 +340,17 @@ preArr bnds = tabulate bnds . preorderF ------------------------------------------------------------ \begin{code} ---postorder :: Tree a -> [a] -postorder (Node a ts) = postorderF ts ++ [a] +postorder :: Tree a -> [a] -> [a] +postorder (Node a ts) = postorderF ts . (a :) -postorderF :: Forest a -> [a] -postorderF ts = concat (map postorder ts) +postorderF :: Forest a -> [a] -> [a] +postorderF ts = foldr (.) id $ map postorder ts -postOrd :: Graph -> [Vertex] -postOrd = postorderF . dff +postOrd :: Graph -> [Vertex] +postOrd g = postorderF (dff g) [] -topSort :: Graph -> [Vertex] -topSort = reverse . postOrd +topSort :: Graph -> [Vertex] +topSort = reverse . postOrd \end{code}