:: ROGraph a = ROGraph a [ROGraph a]
:: RODGraph a = RODGraph a [RODGraph a] [RODGraph a]
buildROGraph :: (a b (c,[b])) -> Map b (ROGraph c) | Lookup MapOnList b & UpdateDefault MapOnList b & Pairs a
buildROGraph m = buildGraph m \ id val fws bws = ROGraph val fws
buildRODGraph m = buildGraph m \ id val fws bws = RODGraph val fws bws
buildGraph rawGraph constructor = futureIndex
where
raw = pairs rawGraph
forwards = buildFastMap $ flip map raw \ (id,(a,fws)) = (id,fws)
backwards = buildBackwards forwards
futureIndex = buildFastMap $ flip map raw \ (id,(a,fws)) = (id,build id a fws)
fromFuture ids = map (fromJustXXX o lookup futureIndex) ids
build nodeId contents forwards
# backwards = case lookup backwards nodeId of Just x -> x ; _ -> []
= constructor nodeId contents (fromFuture forwards) (fromFuture backwards)
buildBackwards :: (a b [c]) -> a c [b] | Empty (a c [b]) & Pairs a & UpdateDefault a c
buildBackwards graph = seqMap processNode (pairs graph) empty
where
processNode (id,forwards) = seqMapLFA forwards \ fr m = snd $ updateDefault fr (cons id) [] m
testGraph :: Map Int (Int,[Int])
testGraph = fromPairs [ @1 [2,3,4], @2 [4,1], @3 [1,2], @4 [3,4] ]
where
@ a b = (a,(a,b))
Start = printRODGraph $ fromJust $ lookup (buildRODGraph testGraph) 1
Tuesday, March 3, 2009
Read Only True Graph Builder In Functional Language
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment