module Language.Lexer.Tlex.Data.Graph (
    transClosure,
) where

import qualified Data.Array    as Array
import           Data.Foldable
import qualified Data.Graph    as Graph

transClosure :: Graph.Graph -> Graph.Graph
transClosure :: Graph -> Graph
transClosure Graph
gr = forall i e. Ix i => (i, i) -> [e] -> Array i e
Array.listArray (Vertex, Vertex)
r [ Vertex -> [Vertex]
goDfs Vertex
v | Vertex
v <- Graph -> [Vertex]
Graph.vertices Graph
gr ] where
    r :: (Vertex, Vertex)
r = forall i e. Array i e -> (i, i)
Array.bounds Graph
gr

    goDfs :: Vertex -> [Vertex]
goDfs Vertex
v = forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\Tree Vertex
t -> forall (t :: * -> *) a. Foldable t => t a -> [a]
toList Tree Vertex
t) do Graph -> [Vertex] -> [Tree Vertex]
Graph.dfs Graph
gr [Vertex
v]