X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=hs-rrdtool.git;a=blobdiff_plain;f=Types%2FData%2FGraph%2FRootPath.hs;fp=Types%2FData%2FGraph%2FRootPath.hs;h=753f331fc355a7b722718fd1b1594790fa38670a;hp=0000000000000000000000000000000000000000;hb=a370bc29f91d16ad36da733fb82061b9a543700e;hpb=315cb18674266b201bd9eb48efb60edd1f30c41f diff --git a/Types/Data/Graph/RootPath.hs b/Types/Data/Graph/RootPath.hs new file mode 100644 index 0000000..753f331 --- /dev/null +++ b/Types/Data/Graph/RootPath.hs @@ -0,0 +1,55 @@ +{-# LANGUAGE + EmptyDataDecls, + TypeFamilies, + UndecidableInstances + #-} +module Types.Data.Graph.RootPath + ( GetLPath + , GetDistance + , GetLPathNodes + ) + where + +import qualified Types.Data.List as L +import qualified Types.Data.List.Ops as L + +import Types.Data.Bool +import Types.Data.Graph +import Types.Data.Ord + +-- NodeID +type family NodeID lNode +type instance NodeID (LNode nodeID nodeLabel) = nodeID + +-- NodeIDA +data NodeIDA +type instance L.App NodeIDA lNode = NodeID lNode + +-- NodeLabel +type family NodeLabel lNode +type instance NodeLabel (LNode nodeID nodeLabel) = nodeLabel + +-- FindP +type family FindP node lPaths +type instance FindP n L.Null = L.Null +type instance FindP n (L.Cons (LPath L.Null) ps) = FindP n ps +type instance FindP n (L.Cons (LPath (L.Cons (LNode n' l) ns)) ps) + = If (n :==: n') + (L.Cons (LNode n' l) ns) + (FindP n ps) + +-- GetLPath +type GetLPath node lPaths + = LPath (GetLPath' node lPaths) + +-- GetLPath' +type GetLPath' node lPaths + = L.Reverse (FindP node lPaths) + +-- GetDistance +type GetDistance node lPaths + = NodeLabel (L.Head (FindP node lPaths)) + +-- GetLPathNodes +type GetLPathNodes node lPaths + = L.Map NodeIDA (GetLPath' node lPaths)