Graph.hs revision d25e031323420dd9bda4dd19407e9fb0349d442b
Tree-based implementation of 'Graph' and 'DynGraph' using Common.Lib.Map
instead of Data.Graph.Inductive.Internal.FiniteMap
module Common.Lib.Graph (Gr(..)) where
import Data.Graph.Inductive.Graph
import qualified Common.Lib.Map as Map
newtype Gr a b = Gr { toMap :: Map.Map Node (Adj b, a, Adj b) }
type GraphRep a b = Map.Map Node (Context' a b)
empty = Gr Map.empty
isEmpty (Gr g) = Map.null g
labNodes (Gr g) = map (\(v,(_,l,_))->(v,l)) (Map.toList g)
matchAny (Gr g) = if Map.null g then error "Match Exception, Empty Graph"
else (c,g') where (Just c,g') = matchGr (fst $ Map.findMin g) (Gr g)
noNodes (Gr g) = Map.size g
nodeRange (Gr g) = if Map.null g then (0, -1)
concatMap (\(v,(_,_,s))->map (\(l,w)->(v,w,l)) s) (Map.toList g)
(p,v,l,s) & (Gr g) | Map.member v g =
where g1 = Map.insert v (p,l,s) g
$ Map.toList gr
case Map.lookup v g of
g' = Map.delete v g