Mercurial > hg > Members > toma > Jungle-haskell
changeset 3:090bdde20e9f
add Main.hs
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 26 Mar 2013 18:28:54 +0900 |
parents | 392c3f30c076 |
children | 48ed16468aaa |
files | Jungle.hs Main.hs |
diffstat | 2 files changed, 23 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Jungle.hs Tue Mar 26 17:30:20 2013 +0900 +++ b/Jungle.hs Tue Mar 26 18:28:54 2013 +0900 @@ -1,7 +1,7 @@ module Jungle ( Jungle , Tree -, Node +, Node (Empty) , Children , Attributes , createJungle @@ -19,9 +19,10 @@ ) where import qualified Data.Map as Map +import qualified Data.ByteString as B data Children = Children (Map.Map Int Node) deriving (Show) -data Attributes = Attributes (Map.Map String String) deriving (Show) +data Attributes = Attributes (Map.Map String B.ByteString) deriving (Show) data Node = Empty | Node @@ -62,8 +63,8 @@ at :: Children -> Int -> Node at (Children map) pos = Map.findWithDefault Empty pos map -get :: Attributes -> String -> String -get (Attributes map) key = Map.findWithDefault "" key map +get :: Attributes -> String -> B.ByteString +get (Attributes map) key = Map.findWithDefault B.empty key map addNewChildAt :: Tree -> Path -> Int -> Node -> Tree addNewChildAt tree path pos node = Tree $ addNewChildAt' (getRootNode tree) path pos node @@ -94,7 +95,7 @@ deleteChild Empty _ = Empty deleteChild (Node (Children map) attributes) pos = Node (Children (Map.delete pos map)) attributes -putAttribute :: Tree -> Path -> String -> String -> Tree +putAttribute :: Tree -> Path -> String -> B.ByteString -> Tree putAttribute tree path key value = editTree tree path (putAttribute' target key value) where root = getRootNode tree @@ -106,7 +107,7 @@ root = getRootNode tree target = getNode root path -putAttribute' :: Node -> String -> String -> Node +putAttribute' :: Node -> String -> B.ByteString -> Node putAttribute' Empty key value = putAttribute' (Node (Children Map.empty) (Attributes Map.empty)) key value putAttribute' (Node children (Attributes map)) key value = Node children (Attributes (Map.insert key value map))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Main.hs Tue Mar 26 18:28:54 2013 +0900 @@ -0,0 +1,16 @@ +module Main where +import Jungle +import qualified Data.ByteString.Char8 as C + + +x = createTree createJungle "new_tree" +tree = getTreeByName x "new_tree" +new_tree = addNewChildAt tree [] 0 Empty +new_tree2 = putAttribute tree [] "key" (C.pack "value") + + +main = do print $ createJungle + print x + print $ getTreeByName x "new_tree" + print new_tree + print new_tree2