summaryrefslogtreecommitdiff
path: root/tree.py
diff options
context:
space:
mode:
authorDavid Douard <david.douard@logilab.fr>2007-05-04 12:08:03 +0200
committerDavid Douard <david.douard@logilab.fr>2007-05-04 12:08:03 +0200
commitc72d0926d35b214e9b20711161967fc8adff27d4 (patch)
tree9a6033b93749f2fba81269ece36225a0be0e3080 /tree.py
parent4d8ffbb3a788404b8ed15d0558a312e5b821b825 (diff)
downloadlogilab-common-c72d0926d35b214e9b20711161967fc8adff27d4.tar.gz
added 2 methods to Node (tree.py): depth_down() (name could be bettern, though) and width()
Diffstat (limited to 'tree.py')
-rw-r--r--tree.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/tree.py b/tree.py
index 87f7076..551c2d2 100644
--- a/tree.py
+++ b/tree.py
@@ -163,6 +163,20 @@ class Node :
else :
return 0
+ def depth_down(self):
+ """
+ return depth of the tree from this node
+ """
+ if self.children:
+ return 1 + max([c.depth_down() for c in self.children])
+ return 1
+
+ def width(self):
+ """
+ return the width of the tree from this node
+ """
+ return len(self.leaves())
+
def root(self):
"""
return the root node of the tree