aboutsummaryrefslogtreecommitdiff
path: root/util/Search.py
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2010-12-29 17:27:33 -0500
committerGravatar rcoh <rcoh@mit.edu>2010-12-29 17:27:33 -0500
commit93dfb8e3003b483c1041c6f7b4ff293935aeb7c0 (patch)
tree6b0e336f664fa519cad164756b68840e56b50b16 /util/Search.py
parentc8209d01f9ddf4c6670caee08073924cb33e447f (diff)
Inheritence now happens at all levels on reading of config files. No additional resolution of
inheritances should be necessary. RCOH
Diffstat (limited to 'util/Search.py')
-rw-r--r--util/Search.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/util/Search.py b/util/Search.py
index 25882da..f7e4b81 100644
--- a/util/Search.py
+++ b/util/Search.py
@@ -6,3 +6,17 @@ def find_le(a, x):
def find_ge(a, x):
'Find leftmost value greater than x'
return bisect_left(a, x)
+#returns parents of nodes that meed a given condition
+def parental_tree_search(root, childrenstr, conditionstr):
+ ret = []
+ queue = [root]
+ while queue:
+ current = queue.pop()
+ children = eval('current'+childrenstr)
+ for child in children:
+ if eval('child'+conditionstr):
+ ret.append(current)
+ #we know have a tree, so there are no back-edges etc, so no checking of that kind is
+ #necessary
+ queue += children
+ return ret