equal
deleted
inserted
replaced
144 def merge_dicts(dict1, dict2): |
144 def merge_dicts(dict1, dict2): |
145 """update a copy of `dict1` with `dict2`""" |
145 """update a copy of `dict1` with `dict2`""" |
146 dict1 = dict(dict1) |
146 dict1 = dict(dict1) |
147 dict1.update(dict2) |
147 dict1.update(dict2) |
148 return dict1 |
148 return dict1 |
|
149 |
|
150 |
|
151 # use networkX instead ? |
|
152 # http://networkx.lanl.gov/reference/algorithms.traversal.html#module-networkx.algorithms.traversal.astar |
|
153 def transitive_closure_of(entity, relname, _seen=None): |
|
154 if _seen is None: |
|
155 _seen = set() |
|
156 _seen.add(entity.eid) |
|
157 yield entity |
|
158 for child in getattr(entity, relname): |
|
159 if child.eid in _seen: |
|
160 continue |
|
161 for subchild in transitive_closure_of(child, relname, _seen): |
|
162 yield subchild |
149 |
163 |
150 |
164 |
151 class SizeConstrainedList(list): |
165 class SizeConstrainedList(list): |
152 """simple list that makes sure the list does not get bigger |
166 """simple list that makes sure the list does not get bigger |
153 than a given size. |
167 than a given size. |