def query(root, value, visualize=0): out = [ ] # placeholder to store all the intervals which contain the query point vis_arr = [] # for visualizing the search curr = root while True: # check whether the current node has intervals corresponding to it, if yes, then add those if len(curr.getIntervalArr()) > 0: out.extend(curr.getIntervalArr()) if visualize: vis_arr.append(copy.deepcopy(curr)) if curr.getLeftChild() != None: # checks whether to move towards the left if Interval.liesOnInterval(curr.getLeftChild().getInterval(), value) or Interval.liesInInterval( curr.getLeftChild().getInterval(), value): curr = curr.getLeftChild() continue if curr.getRightChild() != None: # checks whether to move towards the right if Interval.liesOnInterval(curr.getRightChild().getInterval(), value) or Interval.liesInInterval( curr.getRightChild().getInterval(), value): curr = curr.getRightChild() continue # returns the list of intervals or nodes if visualize: return vis_arr return out