utils.py
branchstable
changeset 3882 addc715f4fcd
parent 3851 3a18a0a24411
child 3890 d7a270f50f54
child 3902 a0efb0326021
--- a/utils.py	Thu Nov 19 18:01:57 2009 +0100
+++ b/utils.py	Thu Nov 19 18:02:04 2009 +0100
@@ -148,6 +148,20 @@
     return dict1
 
 
+# use networkX instead ?
+# http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar
+def transitive_closure_of(entity, relname, _seen=None):
+    if _seen is None:
+        _seen = set()
+    _seen.add(entity.eid)
+    yield entity
+    for child in getattr(entity, relname):
+        if child.eid in _seen:
+            continue
+        for subchild in transitive_closure_of(child, relname, _seen):
+            yield subchild
+
+
 class SizeConstrainedList(list):
     """simple list that makes sure the list does not get bigger
     than a given size.