/* Get the next prio_tree_node that overlaps with the input interval in iter  */
struct prio_tree_node* prio_tree_next(struct prio_tree_iter *iter)
/* Get the next prio_tree_node that overlaps with the input interval in iter  */
struct prio_tree_node* prio_tree_next(struct prio_tree_iter *iter)
{
	unsigned long r_index, h_index;
	if (iter->cur == NULL)
		return prio_tree_first(iter);
repeat:
	while (prio_tree_left(iter, &r_index, &h_index))
		if (overlap(iter, r_index, h_index))
			return iter->cur;
	while (!prio_tree_right(iter, &r_index, &h_index)) {
	    	while (!prio_tree_root(iter->cur) &&
				iter->cur->parent->right == iter->cur)
			prio_tree_parent(iter);
		if (prio_tree_root(iter->cur))
			return NULL;
		prio_tree_parent(iter);
	}
	if (overlap(iter, r_index, h_index))
		return iter->cur;
	goto repeat;
}