let find_intersecting_elem lo hi t =
let rec loop = function
| [] -> None
| h :: t -> match h with
| Empty -> loop t
| Node n ->
if interval_overlap lo hi n.left_end n.right_end then (
let t = n.left :: n.right :: t in
if interval_overlap lo hi n.lo n.hi
then Some (node_contents n, t)
else loop t
)
else loop t
in
Stream.unfold [t] loop