module Data.Graph.Inductive.Query.BCC(
bcc
) where
import Data.Graph.Inductive.Graph
import Data.Graph.Inductive.Query.ArtPoint
import Data.Graph.Inductive.Query.DFS
gComponents :: (DynGraph gr) => gr a b -> [gr a b]
gComponents g = zipWith mkGraph ln le
where ln = map (\x->[(u,l)|(u,l)<-vs,u `elem` x]) cc
le = map (\x->[(u,v,l)|(u,v,l)<-es,u `elem` x]) cc
(vs,es,cc) = (labNodes g,labEdges g,components g)
embedContexts :: (DynGraph gr) => Context a b -> [gr a b] -> [gr a b]
embedContexts (_,v,l,s) gs = zipWith (&) lc gs
where lc = map (\e->(e,v,l,e)) lc'
lc'= map (\g->[ e | e <- s, gelem (snd e) g]) gs
findGraph :: (DynGraph gr) => Node -> [gr a b] -> (Decomp gr a b, [gr a b])
findGraph _ [] = error "findGraph: empty graph list"
findGraph v (g:gs) = case match v g of
(Nothing, g') -> let (d, gs') = findGraph v gs
in (d, g' : gs')
(Just c, g') -> ((Just c, g'), gs)
splitGraphs :: (DynGraph gr) => [gr a b] -> [Node] -> [gr a b]
splitGraphs gs [] = gs
splitGraphs [] _ = error "splitGraphs: empty graph list"
splitGraphs gs (v:vs) = splitGraphs (gs''++gs''') vs
where gs'' = embedContexts c gs'
gs' = gComponents g'
((Just c,g'), gs''') = findGraph v gs
bcc :: (DynGraph gr) => gr a b -> [gr a b]
bcc g = splitGraphs [g] (ap g)