public class IntervalTree extends RedBlackTree
IntervalTree is a mutable collection
of IntervalTree.Intervals. IntervalTrees support
efficient lookup of overlapping elements.
Every element in an IntervalTree must be an
IntervalTree.Interval. Thus element lookup is done based upon
IntervalTree.Intervals, not on the datum assocatied with each
IntervalTree.Interval.
The intervals maintained by this structure are considered to be closed intervals.
To make use of an IntervalTree cleaner, a
convenience method, addInterval is provided.
addInterval(java.lang.Object, int, int),
"CLR section 15.3, (page 290)."| Modifier and Type | Class and Description |
|---|---|
static class |
IntervalTree.Interval
Immutable record representing a closed interval
[
low,high] holding an object
obj. |
RedBlackTree.RBNodeBinaryTree.Nodecomp, NIL| Constructor and Description |
|---|
IntervalTree()
Constructs a new empty
IntervalTree. |
| Modifier and Type | Method and Description |
|---|---|
IntervalTree.Interval |
addInterval(java.lang.Object datum,
int low,
int high)
Constructs a new
IntervalTree.Interval i and adds
i to this. |
java.util.Iterator |
allOverlapping(IntervalTree.Interval i)
|
static void |
main(java.lang.String[] args) |
protected BinaryTree.Node |
makeNode(java.lang.Object o)
requires: o is-a
IntervalTree.Interval. |
IntervalTree.Interval |
searchOverlapping(IntervalTree.Interval i)
Returns some
IntervalTree.Interval in this which
overlaps the bounds defined by the argument interval
i, or null if no such interval
exists. |
protected BinaryTree.Node |
setLeft(BinaryTree.Node p,
BinaryTree.Node l)
Sets the left child of p.
|
protected BinaryTree.Node |
setParent(BinaryTree.Node c,
BinaryTree.Node p)
Sets the parent of p.
|
protected BinaryTree.Node |
setRight(BinaryTree.Node p,
BinaryTree.Node r)
Sets the right child of p.
|
deleteNode, insertNode, leftRotate, rbDeleteFixup, rightRotate, swapPositionspublic IntervalTree()
IntervalTree.protected BinaryTree.Node makeNode(java.lang.Object o)
IntervalTree.Interval.makeNode in class RedBlackTreeprotected BinaryTree.Node setLeft(BinaryTree.Node p, BinaryTree.Node l)
BinaryTreesetLeft in class BinaryTreeprotected BinaryTree.Node setRight(BinaryTree.Node p, BinaryTree.Node r)
BinaryTreesetRight in class BinaryTreeprotected BinaryTree.Node setParent(BinaryTree.Node c, BinaryTree.Node p)
BinaryTreesetParent in class BinaryTreepublic IntervalTree.Interval searchOverlapping(IntervalTree.Interval i)
IntervalTree.Interval in this which
overlaps the bounds defined by the argument interval
i, or null if no such interval
exists.
This operation is named "Interval-Search" in CLR
public java.util.Iterator allOverlapping(IntervalTree.Interval i)
public IntervalTree.Interval addInterval(java.lang.Object datum, int low, int high)
IntervalTree.Interval i and adds
i to this.
Convenience method.
Requires: high > low.
datum can be null.public static void main(java.lang.String[] args)
Copyright (c) 2006 C. Scott Ananian