Mercurial > hg > Members > toma > Jungle-haskell
changeset 5:afdd87f73f17
fix API
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 17 Jun 2013 18:09:37 +0900 |
parents | 48ed16468aaa |
children | 8bba94ec8c63 |
files | Jungle.hs |
diffstat | 1 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Jungle.hs Tue Apr 09 17:40:00 2013 +0900 +++ b/Jungle.hs Mon Jun 17 18:09:37 2013 +0900 @@ -7,10 +7,12 @@ , Path , createJungle , createTree +, createNode , updateTree , getTreeByName , getRootNode , getChildren +, getMap , getAttributes , at , get @@ -21,7 +23,7 @@ ) where import qualified Data.Map as Map -import qualified Data.ByteString as B +import qualified Data.ByteString.Lazy.Char8 as B data Children = Children (Map.Map Int Node) deriving (Show) data Attributes = Attributes (Map.Map String B.ByteString) deriving (Show) @@ -47,7 +49,10 @@ createTree :: Jungle -> String -> Jungle createTree (Jungle map) tree_name = Jungle (Map.insert tree_name emptyTree map) where - emptyTree = Tree Empty tree_name + emptyTree = Tree createNode tree_name + +createNode :: Node +createNode = Node (Children Map.empty) (Attributes Map.empty) updateTree :: Jungle -> Tree -> Jungle updateTree (Jungle map) tree@(Tree node name) = Jungle (Map.insert name tree map) @@ -55,7 +60,7 @@ getTreeByName :: Jungle -> String -> Tree getTreeByName (Jungle map) tree_name = Map.findWithDefault emptyTree tree_name map where - emptyTree = Tree Empty tree_name + emptyTree = Tree createNode tree_name getRootNode :: Tree -> Node getRootNode tree = rootNode tree @@ -63,6 +68,9 @@ getChildren :: Node -> Children getChildren node = children node +getMap :: Children -> Map.Map Int Node +getMap (Children map) = map + getAttributes :: Node -> Attributes getAttributes node = attributes node