Mercurial > hg > Members > toma > Jungle-haskell
annotate Jungle.hs @ 19:824543aea6fc
delete Children and Attributes
author | Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 24 Jan 2014 00:15:31 +0900 |
parents | 7360fbfc7e62 |
children | 97d1e67aef15 |
rev | line source |
---|---|
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
1 module Jungle |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
2 ( Jungle |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
3 , Node |
4 | 4 , Path |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
5 , Position |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
6 , createJungle |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
7 , createTree |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
8 , getRootNode |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
9 , updateRootNode |
10
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
10 , updateRootNodeWith |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
11 , addNewChildAt |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
12 , deleteChildAt |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
13 , putAttribute |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
14 , deleteAttribute |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
15 , getAttributes |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
16 , getChildren |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
17 , assocs |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
18 , numOfChild |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
19 , currentChild |
8 | 20 , drawNode |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
21 , printAttributes |
8 | 22 , size |
17 | 23 , attrSize |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
24 ) where |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
26 import qualified Data.Map as M |
5 | 27 import qualified Data.ByteString.Lazy.Char8 as B |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
28 import Control.Concurrent.STM |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
29 import Data.Maybe (fromJust) |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
30 |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
31 data Jungle = Jungle { getJungleMap :: (M.Map String Tree) } |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
32 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
33 data Tree = Tree |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
34 { rootNode :: (TVar Node) |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
35 , treeName :: String } |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
36 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
37 data Node = Node |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
38 { children :: (M.Map Int Node) |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
39 , attributes :: (M.Map String B.ByteString) } |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
40 |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
41 type Path = [Int] |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
42 type Position = Int |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
43 |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
44 createJungle :: Jungle |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
45 createJungle = Jungle M.empty |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
46 |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
47 -- 同じ名前のTreeが存在する場合、上書きする |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
48 -- Eitherなどで失敗させるほうがいいかもしれない |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
49 createTree :: Jungle -> String -> IO Jungle |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
50 createTree (Jungle map) tree_name = atomically $ do |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
51 tree <- emptyTree tree_name |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
52 return (Jungle (M.insert tree_name tree map)) |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
53 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
54 emptyTree :: String -> STM Tree |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
55 emptyTree tree_name = do |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
56 node <- newTVar emptyNode |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
57 return (Tree node tree_name) |
5 | 58 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
59 emptyNode :: Node |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
60 emptyNode = Node (M.empty) (M.empty) |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
61 |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
62 -- getRootNodeやupdateRootNodeをJungleとTree名を取るようにしたため不要 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
63 getTreeByName :: Jungle -> String -> Maybe Tree |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
64 getTreeByName (Jungle map) tree_name = M.lookup tree_name map |
4 | 65 |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
66 getRootNode :: Jungle -> String -> IO Node |
10
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
67 getRootNode (Jungle map) tree_name = atomically $ readTVar root_node |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
68 where |
10
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
69 root_node = case M.lookup tree_name map of |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
70 Just x -> rootNode x |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
71 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
72 -- ルートノードを更新する |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
73 updateRootNode :: Jungle -> String -> Node -> IO () |
10
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
74 updateRootNode (Jungle map) tree_name node = atomically $ writeTVar root_node node |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
75 where |
10
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
76 root_node = case M.lookup tree_name map of |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
77 Just x -> rootNode x |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
78 |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
79 updateRootNodeWith :: (Node -> Node) -> Jungle -> String -> IO () |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
80 updateRootNodeWith f (Jungle map) tree_name = |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
81 atomically $ do |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
82 n <- readTVar root_node |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
83 writeTVar root_node (f n) |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
84 where |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
85 root_node = case M.lookup tree_name map of |
29d0f605efa9
add updateRootNodeWith
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
9
diff
changeset
|
86 Just x -> rootNode x |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
87 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
88 -- 新しい木構造を作成し、最新のルートノードとなるNodeを返す |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
89 -- Pathの位置にNodeが存在しない場合どうするか? |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
90 -- 1 -> 2 -> 3と勝手にPositionをインクリメントしながら追加する |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
91 addNewChildAt :: Node -> Path -> Node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
92 addNewChildAt parent [] = addChild' parent emptyNode |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
93 addNewChildAt parent (x:xs) = addChild parent x $ addNewChildAt x_node xs |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
94 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
95 map = children parent |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
96 x_node = case M.lookup x map of |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
97 Just x -> x |
5 | 98 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
99 -- 子を追加したNodeを新しく作成して返す |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
100 -- 同じ位置に既に子がある場合は? |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
101 -- 現在はinsertでそのまま上書き |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
102 addChild :: Node -> Position -> Node -> Node |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
103 addChild node pos child = Node new_child attr |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
104 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
105 map = children node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
106 new_child = M.insert pos child map |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
107 attr = attributes node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
108 |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
109 -- 自動でPositionをincrementして追加してくれるaddChild |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
110 addChild' :: Node -> Node -> Node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
111 addChild' node child = Node new_child attr |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
112 where |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
113 map = children node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
114 pos = (M.size map) + 1 |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
115 new_child = M.insert pos child map |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
116 attr = attributes node |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
117 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
118 -- 子を削除した新しいNodeを追加するのに等しい |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
119 deleteChildAt :: Node -> Path -> Position -> Node |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
120 deleteChildAt parent [] pos = deleteChild parent pos |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
121 deleteChildAt parent (x:xs) pos = addChild parent x $ deleteChildAt x_node xs pos |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
122 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
123 map = children parent |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
124 x_node = case M.lookup x map of |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
125 Just x -> x |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
126 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
127 deleteChild :: Node -> Position -> Node |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
128 deleteChild node pos = Node new_child attr |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
129 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
130 map = children node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
131 new_child = M.delete pos map |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
132 attr = attributes node |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
133 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
134 -- attribute関連はaddNewChildAtを利用する |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
135 -- 現在はコピペ、関数に抽出したい |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
136 putAttribute :: Node -> Path -> String -> B.ByteString -> Node |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
137 putAttribute parent [] key value = putAttr parent key value |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
138 putAttribute parent (x:xs) key value = addChild parent x $ putAttribute x_node xs key value |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
139 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
140 map = children parent |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
141 x_node = case M.lookup x map of |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
142 Just x -> x |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
143 |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
144 putAttr :: Node -> String -> B.ByteString -> Node |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
145 putAttr node key value = Node child attr |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
146 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
147 map = attributes node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
148 attr = M.insert key value map |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
149 child = children node |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
150 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
151 deleteAttribute :: Node -> Path -> String -> Node |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
152 deleteAttribute parent [] key = deleteAttr parent key |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
153 deleteAttribute parent (x:xs) key = addChild parent x $ deleteAttribute x_node xs key |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
154 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
155 map = children parent |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
156 x_node = case M.lookup x map of |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
157 Just x -> x |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
158 |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
159 deleteAttr :: Node -> String -> Node |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
160 deleteAttr node key = Node child attr |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
161 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
162 map = attributes node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
163 attr = M.delete key map |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
164 child = children node |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
165 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
166 -- データを取り出す関連の関数 |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
167 -- getNodeとgetchild, getattributeなど? |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
168 |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
169 getNode :: Node -> Path -> Node |
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
170 getNode node [] = node |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
171 getNode node (x:xs) = getNode child xs |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
172 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
173 map = children node |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
174 child = case M.lookup x map of |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
175 Just x -> x |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
176 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
177 getAttributes :: Node -> Path -> String -> Maybe B.ByteString |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
178 getAttributes node path key = M.lookup key map |
1
98e1a35e4ab0
Rewrite almost and Modularization
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
0
diff
changeset
|
179 where |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
180 target = getNode node path |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
181 map = attributes target |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
182 |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
183 -- 対象のNodeの全ての子を返す |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
184 getChildren :: Node -> Path -> [Node] |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
185 getChildren node path = M.elems map |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
186 where |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
187 target = getNode node path |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
188 map = children target |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
189 |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
190 -- Attributeの連想リストを返す |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
191 assocs :: Node -> Path -> [(String, B.ByteString)] |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
192 assocs node path = M.assocs map |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
193 where |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
194 target = getNode node path |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
195 map = attributes target |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
196 |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
197 -- 対象のNodeの子供の数を教えてくれる |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
198 numOfChild :: Node -> Path -> Int |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
199 numOfChild node path = M.size map |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
200 where |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
201 target = getNode node path |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
202 map = children target |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
203 |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
204 -- foucus |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
205 -- 対象のpathのノードの最新の子を返す |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
206 -- 編集する際に使うのは無理 |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
207 currentChild :: Node -> Path -> Maybe Node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
208 currentChild node path = M.lookup pos map |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
209 where |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
210 target = getNode node path |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
211 map = children target |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
212 pos = M.size map |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
213 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
214 -- デバッグ用表示関数 |
8 | 215 |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
216 -- 現在の木構造を整形して表示 |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
217 drawNode :: Node -> String |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
218 drawNode node = unlines $ draw "root" node |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
219 |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
220 draw :: String -> Node -> [String] |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
221 draw string node = string : drawSubTrees keys |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
222 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
223 map = children node |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
224 keys = M.keys map |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
225 drawSubTrees [] = [] |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
226 drawSubTrees [t] = |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
227 "|" : shift "`- " " " (draw (show t) (fromJust $ M.lookup t map)) |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
228 drawSubTrees (t:ts) = |
6
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
229 "|" : shift "+- " "| " (draw (show t) (fromJust $ M.lookup t map )) ++ drawSubTrees ts |
8bba94ec8c63
add STM to the root node.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
5
diff
changeset
|
230 shift first other = zipWith (++) (first : repeat other) |
0
329f462d5dad
add nondestructive tree structure.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
231 |
9
947c5cfa4149
Change function related to Tree, Tree is not visiable from outside.
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
8
diff
changeset
|
232 -- Attributesを全て表示 |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
233 printAttributes :: Node -> String |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
234 printAttributes node = unlines $ printAttr "root" node |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
235 |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
236 printAttr :: String -> Node -> [String] |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
237 printAttr string node = |
8 | 238 if not $ M.null attr_map |
239 then ("Node: " ++ string) : (" " ++ attr) : printSubTrees keys | |
240 else printSubTrees keys | |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
241 where |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
242 attr_map = attributes node |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
243 show_attr [] = [] |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
244 show_attr [x] = fst x ++ ": " ++ (B.unpack $ snd x) |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
245 show_attr (x:xs) = fst x ++ ": " ++ (B.unpack $ snd x) ++ "\n " ++ show_attr xs |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
246 attr = show_attr $ M.assocs attr_map |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
247 map = children node |
7
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
248 keys = M.keys map |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
249 printSubTrees [] = [] |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
250 printSubTrees (x:xs) = printAttr (string ++ "-" ++ (show x)) (fromJust $ M.lookup x map) ++ printSubTrees xs |
644e1345ee83
add debugging function
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
6
diff
changeset
|
251 |
8 | 252 -- ルートノードの下にいくつの子があるか数える |
253 size :: Node -> Int | |
254 size node = M.size map + subTreesSize keys | |
255 where | |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
256 map = children node |
8 | 257 keys = M.keys map |
258 subTreesSize [] = 0 | |
259 subTreesSize (x:xs) = size (getNode x) + subTreesSize xs | |
260 getNode x = fromJust $ M.lookup x map | |
261 | |
17 | 262 -- Attributesの数を調べる |
263 attrSize :: Node -> Int | |
264 attrSize node = M.size attr_map + subTreesSize keys | |
265 where | |
19
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
266 attr_map = attributes node |
824543aea6fc
delete Children and Attributes
Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
parents:
17
diff
changeset
|
267 map = children node |
17 | 268 keys = M.keys map |
269 subTreesSize [] = 0 | |
270 subTreesSize (x:xs) = attrSize (getNode x) + subTreesSize xs | |
271 getNode x = fromJust $ M.lookup x map | |
272 |