# HG changeset patch # User Daichi TOMA # Date 1364290134 -32400 # Node ID 090bdde20e9f209e3cd9f8be7c6b9aa6e418f395 # Parent 392c3f30c0763faee511d159d716967ca68c2ea9 add Main.hs diff -r 392c3f30c076 -r 090bdde20e9f Jungle.hs --- 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)) diff -r 392c3f30c076 -r 090bdde20e9f Main.hs --- /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