public class IntervalTree<V> extends java.lang.Object implements java.lang.Iterable<IntervalTree.Node<V>>
Modifier and Type | Class and Description |
---|---|
class |
IntervalTree.FwdIterator |
static class |
IntervalTree.Node<V1> |
class |
IntervalTree.OverlapIterator |
class |
IntervalTree.RevIterator |
static class |
IntervalTree.ValuesIterator<V1> |
Constructor and Description |
---|
IntervalTree() |
Modifier and Type | Method and Description |
---|---|
void |
checkMaxEnds()
This method is only for debugging.
|
void |
clear()
Remove all entries.
|
IntervalTree.Node<V> |
find(int start,
int end)
Find an interval.
|
IntervalTree.Node<V> |
findByIndex(int idx)
Find the nth interval in the tree.
|
int |
getIndex(int start,
int end)
Find the rank of the specified interval.
|
V |
getSentinel()
Get the special sentinel value that will be used to signal novelty when putting a new interval
into the tree, or to signal "not found" when removing an interval.
|
java.util.Iterator<IntervalTree.Node<V>> |
iterator()
Return an iterator over the entire tree.
|
java.util.Iterator<IntervalTree.Node<V>> |
iterator(int start,
int end)
Return an iterator over all intervals greater than or equal to the specified interval.
|
IntervalTree.Node<V> |
max()
Find the greatest interval in the tree.
|
IntervalTree.Node<V> |
max(int start,
int end)
Find the latest interval in the tree less than or equal to the specified interval.
|
V |
merge(int start,
int end,
V value,
java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
If the specified start and end positions are not already associated with a value or are
associated with the sentinel ( see
getSentinel() , associates it with the given (non-sentinel) value. |
IntervalTree.Node<V> |
min()
Find the least interval in the tree.
|
IntervalTree.Node<V> |
min(int start,
int end)
Find the earliest interval in the tree greater than or equal to the specified interval.
|
IntervalTree.Node<V> |
minOverlapper(int start,
int end)
Find the earliest interval in the tree that overlaps the specified interval.
|
java.util.Iterator<IntervalTree.Node<V>> |
overlappers(int start,
int end)
Return an iterator over all intervals overlapping the specified range.
|
void |
printTree()
This method draws a nested picture of the tree on System.out.
|
V |
put(int start,
int end,
V value)
Put a new interval into the tree (or update the value associated with an existing interval).
|
V |
remove(int start,
int end)
Remove an interval from the tree.
|
java.util.Iterator<IntervalTree.Node<V>> |
reverseIterator()
Return an iterator over the entire tree that returns intervals in reverse order.
|
java.util.Iterator<IntervalTree.Node<V>> |
reverseIterator(int start,
int end)
Return an iterator over all intervals less than or equal to the specified interval, in reverse order.
|
V |
setSentinel(V sentinel)
Set the special sentinel value that will be used to signal novelty when putting a new interval
into the tree, or to signal "not found" when removing an interval.
|
int |
size()
Return the number of intervals in the tree.
|
public int size()
public void clear()
public V put(int start, int end, V value)
start
- The interval's start.end
- The interval's end.value
- The associated value.public V merge(int start, int end, V value, java.util.function.BiFunction<? super V,? super V,? extends V> remappingFunction)
getSentinel()
, associates it with the given (non-sentinel) value.
Otherwise, replaces the associated value with the results of the given
remapping function, or removes if the result is equal to the sentinel value. This
method may be of use when combining multiple values that have the same start and end position.start
- interval start positionend
- interval end positionvalue
- value to merge into the tree, must not be equal to the sentinel valueremappingFunction
- a function that merges the new value with the existing value for the same start and end position,
if the function returns the sentinel value then the mapping will be unsetpublic V remove(int start, int end)
start
- The interval's start.end
- The interval's end.public IntervalTree.Node<V> find(int start, int end)
start
- The interval's start.end
- The interval's end.public IntervalTree.Node<V> findByIndex(int idx)
idx
- The rank of the interval sought (from 0 to size()-1).public int getIndex(int start, int end)
start
- The interval's start.end
- The interval's end.public IntervalTree.Node<V> min()
public IntervalTree.Node<V> min(int start, int end)
start
- The interval's start.end
- The interval's end.public IntervalTree.Node<V> minOverlapper(int start, int end)
start
- The interval's start.end
- The interval's end.public IntervalTree.Node<V> max()
public IntervalTree.Node<V> max(int start, int end)
start
- The interval's start.end
- The interval's end.public java.util.Iterator<IntervalTree.Node<V>> iterator()
iterator
in interface java.lang.Iterable<IntervalTree.Node<V>>
public java.util.Iterator<IntervalTree.Node<V>> iterator(int start, int end)
start
- The interval's start.end
- The interval's end.public java.util.Iterator<IntervalTree.Node<V>> overlappers(int start, int end)
start
- The range start.end
- The range end.public java.util.Iterator<IntervalTree.Node<V>> reverseIterator()
public java.util.Iterator<IntervalTree.Node<V>> reverseIterator(int start, int end)
start
- The interval's start.end
- The interval's end.public V getSentinel()
public V setSentinel(V sentinel)
sentinel
- The new sentinel value.public void checkMaxEnds()
java.lang.IllegalStateException
- If an inconsistency is detected.public void printTree()