aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libbe/tree.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/libbe/tree.py b/libbe/tree.py
index 0256407..45ae085 100644
--- a/libbe/tree.py
+++ b/libbe/tree.py
@@ -68,7 +68,18 @@ class Tree(list):
f
h
i
+ >>> a.has_descendant(g)
+ True
+ >>> c.has_descendant(g)
+ False
+ >>> a.has_descendant(a)
+ False
+ >>> a.has_descendant(a, match_self=True)
+ True
"""
+ def __eq__(self, other):
+ return id(self) == id(other)
+
def branch_len(self):
"""
Exhaustive search every time == SLOW.
@@ -157,4 +168,12 @@ class Tree(list):
yield (depth,node)
stack.append(node)
+ def has_descendant(self, descendant, depth_first=True, match_self=False):
+ if descendant == self:
+ return match_self
+ for d in self.traverse(depth_first):
+ if descendant == d:
+ return True
+ return False
+
suite = doctest.DocTestSuite()