Package SmootLight :: Package util :: Module Search
[hide private]
[frames] | no frames]

Source Code for Module SmootLight.util.Search

 1  from bisect import * 
2 -def find_le(a, x):
3 """Find rightmost value less than or equal to x""" 4 return bisect_right(a, x)-1
5
6 -def find_ge(a, x):
7 """Find leftmost value greater than x""" 8 return bisect_left(a, x)
9 -def parental_tree_search(root, childrenstr, conditionstr):
10 """Returns parents of nodes that meed a given condition""" 11 ret = [] 12 queue = [root] 13 while queue: 14 current = queue.pop() 15 children = eval('current'+childrenstr) 16 for child in children: 17 if eval('child'+conditionstr): 18 ret.append(current) 19 #we know have a tree, so there are no back-edges etc, so no checking of that kind is 20 #necessary 21 queue += children 22 return ret
23