A helper function for the IntervalTree#query(Comparable) method. It searches recursively for all intervals stored in the subtree rooted at the current node, that intersect a target point. @param root The root of the currently traversed subtree. May be null. @param point The query po
(TreeNode<T> root, T point, Set<Interval<T>> res)
| 298 | * @return The set of all intervals from the current subtree, containing the query. |
| 299 | */ |
| 300 | public static <T extends Comparable<? super T>> Set<Interval<T>> query(TreeNode<T> root, T point, Set<Interval<T>> res) { |
| 301 | if (root == null) |
| 302 | return res; |
| 303 | if (point.compareTo(root.midpoint) <= 0){ |
| 304 | for (Interval<T> next: root.increasing){ |
| 305 | if (next.isRightOf(point)) |
| 306 | break; |
| 307 | res.add(next); |
| 308 | } |
| 309 | return TreeNode.query(root.left, point, res); |
| 310 | } else{ |
| 311 | for (Interval<T> next: root.decreasing){ |
| 312 | if (next.isLeftOf(point)) |
| 313 | break; |
| 314 | res.add(next); |
| 315 | } |
| 316 | return TreeNode.query(root.right, point, res); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | |
| 321 | /** |