Graph.hs revision c667c643fac66101daf13f48859e6f2441064122
0N/ATree-based implementation of 'Graph' and 'DynGraph' using Data.IntMap
0N/Ainstead of Data.Graph.Inductive.Internal.FiniteMap
0N/Amodule Common.Lib.Graph
0N/Aimport Data.Graph.Inductive.Graph as Graph
0N/Aimport qualified Data.IntMap as Map
0N/Anewtype Gr a b = Gr { convertToMap :: Map.IntMap (GrContext a b) }
0N/A , nodeSuccs :: Map.IntMap [b]
0N/A , nodePreds :: Map.IntMap [b] }
unsafeConstructGr :: Map.IntMap (GrContext a b) -> Gr a b
empty = Gr Map.empty
isEmpty (Gr g) = Map.null g
labNodes = map (\ (v, c) -> (v, nodeLabel c)) . Map.toList . convertToMap
matchAny g = case Map.keys $ convertToMap g of
noNodes (Gr g) = Map.size g
nodeRange (Gr g) = case Map.keys g of
. Map.toList . convertToMap
, nodeSuccs = Map.delete v sm
, nodePreds = Map.delete v pm } gr
showGraph :: (Show a, Show b) => Map.IntMap (GrContext a b) -> String
l -> [(v, l)]) ++ Map.toList (nodeSuccs c)))
$ Map.toList gr
mkAdj :: Map.IntMap [b] -> Adj b
mkAdj = concatMap (\ (w, l) -> map (\ e -> (e, w)) l) . Map.toList
decomposeGr v (Gr g) = case Map.lookup v g of
g1 = Map.delete v g
addSuccs v ls c = c { nodeSuccs = Map.insert v ls $ nodeSuccs c }
addPreds v ls c = c { nodePreds = Map.insert v ls $ nodePreds c }
clearSucc v _ c = c { nodeSuccs = Map.delete v $ nodeSuccs c }
clearPred v _ c = c { nodePreds = Map.delete v $ nodePreds c }
-> ([b] -> GrContext a b -> GrContext a b) -> Map.IntMap (GrContext a b)
updAdj g m f = Map.foldWithKey (\ v -> updGrContext v . f) g m
updGrContext v f r = case Map.lookup v r of
Just c -> Map.insert v (f c) r
g3 = Map.insert v c g2
in if Map.member v g then error $ "Node Exception, Node: " ++ show v
Map.foldWithKey (\ nxt lbls l ->
in Map.foldWithKey (\ nxt lbls ->
(map (\ lbl -> [(src, tgt, lbl)]) $ Map.findWithDefault [] tgt s)
(Map.delete tgt s)
delLEdge cmp (v, w, l) (Gr m) = let e = show (v, w) in case Map.lookup v m of
ls = if b then loops c else Map.findWithDefault [] w sm
([_], rs) -> if b then Gr $ Map.insert v c { loops = rs } m else
$ Map.insert v c
{ nodeSuccs = if null rs then Map.delete w sm else
Map.insert w rs sm } m
let e = show (v, w) in case Map.lookup v m of
ls = if b then loops c else Map.findWithDefault [] w sm
else if b then Gr $ Map.insert v c { loops = ns } m else
labelNode (v, l) (Gr m) = case Map.lookup v m of
Just c -> (Gr $ Map.insert v (c { nodeLabel = l }) m, nodeLabel c)
rmIsolated (Gr m) = Gr $ Map.filter