summaryrefslogtreecommitdiff
path: root/src/Grasp/Edge.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-11-20 22:11:03 +1100
committerJed Barber <jjbarber@y7mail.com>2014-11-20 22:11:03 +1100
commit0c49b3f13dc00eb5811002f230e1a6e4cc52d705 (patch)
tree442992bea3c31abaae0eaa976a3307c5bcc0927e /src/Grasp/Edge.hs
parent54ba705026976ae291ec8259abd83033ca01e4c6 (diff)
Factored out graph node/edge and instruction pointer types
Diffstat (limited to 'src/Grasp/Edge.hs')
-rw-r--r--src/Grasp/Edge.hs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Grasp/Edge.hs b/src/Grasp/Edge.hs
new file mode 100644
index 0000000..f0e1cc3
--- /dev/null
+++ b/src/Grasp/Edge.hs
@@ -0,0 +1,43 @@
+module Grasp.Edge (
+ GEdge,
+ GEdgeType,
+
+ singleton,
+ fromStringList,
+ src,
+ dest,
+ lab
+ ) where
+
+
+
+import Data.Graph.Inductive.Graph( LEdge )
+import Data.Map( Map )
+import qualified Data.Map as Map
+
+
+
+type GEdge = LEdge String
+type GEdgeType = String
+
+
+
+singleton :: Int -> Int -> String -> GEdge
+singleton f t s = (f,t,s)
+
+fromStringList :: Map String Int -> [(String,String,String)] -> [GEdge]
+fromStringList m es =
+ let change x = case (Map.lookup x m) of
+ Just a -> a
+ Nothing -> error "Grasp.Edge.fromStringList: no value for key " ++ x
+ in map (\(x,y,z) -> (change x, change y, z)) es
+
+src :: GEdge -> Int
+src (x,_,_) = x
+
+dest :: GEdge -> Int
+dest (_,x,_) = x
+
+lab :: GEdge -> String
+lab (_,_,x) = x
+