static < T extends Comparable < ? super T > > void rangeQueryRight ( TreeNode < T > node , Interval < T > query , Set < Interval < T > > result ) { while ( node != null ) { if ( query . contains ( node . midpoint ) ) { result . addAll ( node . increasing ) ; if ( node . left != null ) { for ( Interval < T > next : node . left ) result . ( next ) ; } node = node . right ; } else { for ( Interval < T > next : node . increasing ) { if ( next . isRightOf ( query ) ) break ; result . add ( next ) ; } node = node . left ; } } }
A helper method for the range search used in the interval intersection query in the tree . This corresponds to the right branch of the range search once we find a node whose midpoint is contained in the query interval . All intervals in the right subtree of that node are guaranteed to intersect with the query if they have an endpoint smaller or equal than the end of the query interval . Basically this means that every time we branch to the right in the binary search we need to add the whole left subtree to the result set .