utils.py
changeset 6854 ffc982faa264
parent 6684 b8bd0ecced2e
child 6931 0af44a38fe41
equal deleted inserted replaced
6851:824d5b6eae7f 6854:ffc982faa264
   110                 self.w(self.tag.replace('<', '</', 1))
   110                 self.w(self.tag.replace('<', '</', 1))
   111 
   111 
   112 
   112 
   113 # use networkX instead ?
   113 # use networkX instead ?
   114 # http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar
   114 # http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar
   115 def transitive_closure_of(entity, relname, _seen=None):
   115 def transitive_closure_of(entity, rtype, _seen=None):
   116     """return transitive closure *for the subgraph starting from the given
   116     """return transitive closure *for the subgraph starting from the given
   117     entity* (eg 'parent' entities are not included in the results)
   117     entity* (eg 'parent' entities are not included in the results)
   118     """
   118     """
   119     if _seen is None:
   119     if _seen is None:
   120         _seen = set()
   120         _seen = set()
   121     _seen.add(entity.eid)
   121     _seen.add(entity.eid)
   122     yield entity
   122     yield entity
   123     for child in getattr(entity, relname):
   123     for child in getattr(entity, rtype):
   124         if child.eid in _seen:
   124         if child.eid in _seen:
   125             continue
   125             continue
   126         for subchild in transitive_closure_of(child, relname, _seen):
   126         for subchild in transitive_closure_of(child, rtype, _seen):
   127             yield subchild
   127             yield subchild
   128 
   128 
   129 
   129 
   130 class SizeConstrainedList(list):
   130 class SizeConstrainedList(list):
   131     """simple list that makes sure the list does not get bigger
   131     """simple list that makes sure the list does not get bigger