changeset 17:7360fbfc7e62

add attrSize
author Daichi TOMA <toma@cr.ie.u-ryukyu.ac.jp>
date Wed, 22 Jan 2014 15:32:11 +0900
parents 72cc49b616cd
children 8d4e37c1a86a
files Jungle.hs
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Jungle.hs	Wed Jan 22 15:23:36 2014 +0900
+++ b/Jungle.hs	Wed Jan 22 15:32:11 2014 +0900
@@ -16,6 +16,7 @@
 , drawNode
 , printAttributes
 , size
+, attrSize
 ) where
 
 import qualified Data.Map as M
@@ -222,3 +223,14 @@
     subTreesSize (x:xs) = size (getNode x) + subTreesSize xs
     getNode x = fromJust $ M.lookup x map
 
+-- Attributesの数を調べる
+attrSize :: Node -> Int
+attrSize node = M.size attr_map + subTreesSize keys
+  where
+    attr_map = getAttributesMap $ attributes node
+    map = getChildrenMap $ children node
+    keys = M.keys map
+    subTreesSize [] = 0
+    subTreesSize (x:xs) = attrSize (getNode x) + subTreesSize xs
+    getNode x = fromJust $ M.lookup x map
+