diff options
author | David Douard <david.douard@logilab.fr> | 2007-05-04 12:08:03 +0200 |
---|---|---|
committer | David Douard <david.douard@logilab.fr> | 2007-05-04 12:08:03 +0200 |
commit | c72d0926d35b214e9b20711161967fc8adff27d4 (patch) | |
tree | 9a6033b93749f2fba81269ece36225a0be0e3080 /tree.py | |
parent | 4d8ffbb3a788404b8ed15d0558a312e5b821b825 (diff) | |
download | logilab-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.py | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -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 |