public class StaticIntervalTree<U extends Comparable<U>,T extends Interval<U>> extends Object
While this implementation of a static interval tree is built to support a pre-specified set of intervals, intervals from this set may be added to and removed from the tree at will, giving a semi-static nature to the tree. The construction process completes in time O(n*log(n)) where n is the size of the set of intervals with which the tree is built.
Insertion and deletion of intervals to and from a constructed tree completes in time O(log(n)) where n is the size of the set of intervals with which the tree was built.
A constructed tree consumes linear space in the size of the set of intervals with which the tree was built.
Note that this implementation supports all three closed, open and half-open intervals.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
StaticIntervalTree.Node<U extends Comparable<U>,T extends Interval<U>>
A node for a static interval tree is a binary tree node
augmented with an associated point value and the ability to store
intervals.
|
| Constructor and Description |
|---|
StaticIntervalTree()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
buildTree(Set<T> intervals)
Build the interval tree to support the elements of the specified set of
intervals.
|
void |
clear()
Clear the contents of the tree, leaving the tree structure intact.
|
boolean |
delete(T interval)
Delete the specified interval from this tree.
|
<V extends Collection<T>> |
fetchContainingIntervals(V target,
U queryPoint)
Fetch intervals containing the specified point.
|
<V extends Collection<T>> |
fetchOverlappingIntervals(V target,
T queryInterval)
Fetch intervals overlapping the specified interval.
|
int |
getSize()
Get the number of intervals being stored in the tree.
|
boolean |
insert(T interval)
Insert the specified interval into this tree.
|
public void buildTree(Set<T> intervals)
insert(Interval) after the tree is
built).intervals - the set of intervals for which the tree is to be built.public void clear()
public boolean delete(T interval)
interval - the interval to delete.public <V extends Collection<T>> V fetchContainingIntervals(V target, U queryPoint)
target - the target Collection into which to place the desired
intervals.queryPoint - the query point.public <V extends Collection<T>> V fetchOverlappingIntervals(V target, T queryInterval)
target - the target Collection into which to place the desired
intervals.queryInterval - the query interval.public int getSize()
public boolean insert(T interval)
buildTree(Set).interval - the interval to insert.Copyright © 1994–2024 Peter Murray-Rust. All rights reserved.