public class AVLIntervalTree
extends java.lang.Object
implements java.io.Serializable
The purpose of this class is to sort elements while allowing
duplicate elements (i.e. such that a.equals(b)
is
true). The SortedSet
interface does not allow this, so
a specific class is needed. Null elements are not allowed.
Since the equals
method is not sufficient to
differentiate elements, the delete
method is
implemented using the equality operator.
In order to clearly mark the methods provided here do not have
the same semantics as the ones specified in the
SortedSet
interface, different names are used
(add
has been replaced by insert
and
remove
has been replaced by delete
).
This class is based on the C implementation Georg Kraml has put in the public domain. Unfortunately, his page seems not to exist any more.
Modifier and Type | Class and Description |
---|---|
class |
AVLIntervalTree.Node
This class implements AVL trees nodes.
|
Modifier and Type | Field and Description |
---|---|
AVLIntervalTree.Node |
top
Top level node.
|
Constructor and Description |
---|
AVLIntervalTree()
Build an empty tree.
|
Modifier and Type | Method and Description |
---|---|
boolean |
delete(Range element)
Delete an element from the tree.
|
AVLIntervalTree.Node |
getLargest()
Get the node whose element is the largest one in the tree.
|
AVLIntervalTree.Node |
getNotLarger(Range reference)
Get the node whose element is not larger than the reference object.
|
AVLIntervalTree.Node |
getNotSmaller(Range reference)
Get the node whose element is not smaller than the reference object.
|
AVLIntervalTree.Node |
getSmallest()
Get the node whose element is the smallest one in the tree.
|
void |
insert(Range element)
Insert an element in the tree.
|
boolean |
isEmpty()
Check if the tree is empty.
|
void |
printFlatTree(AVLIntervalTree.Node n)
Prints the flat tree.
|
void |
search(AVLIntervalTree.Node n,
java.lang.Double d,
java.util.ArrayList<Range> result)
Search.
|
int |
size()
Get the number of elements of the tree.
|
public AVLIntervalTree.Node top
public void search(AVLIntervalTree.Node n, java.lang.Double d, java.util.ArrayList<Range> result)
n
- the nd
- the dresult
- the resultpublic void printFlatTree(AVLIntervalTree.Node n)
n
- the npublic void insert(Range element)
element
- element to insert (silently ignored if null)public boolean delete(Range element)
The element is deleted only if there is a node n
containing exactly the element instance specified, i.e. for which
n.getElement() == element
. This is purposely
different from the specification of the
java.util.Set
remove
method (in fact,
this is the reason why a specific class has been developed).
element
- element to delete (silently ignored if null)public boolean isEmpty()
public int size()
public AVLIntervalTree.Node getSmallest()
getLargest()
,
getNotSmaller(agents.context.Range)
,
getNotLarger(agents.context.Range)
,
AVLIntervalTree.Node.getPrevious()
,
AVLIntervalTree.Node.getNext()
public AVLIntervalTree.Node getLargest()
getSmallest()
,
getNotSmaller(agents.context.Range)
,
getNotLarger(agents.context.Range)
,
AVLIntervalTree.Node.getPrevious()
,
AVLIntervalTree.Node.getNext()
public AVLIntervalTree.Node getNotSmaller(Range reference)
reference
- reference object (may not be in the tree)getSmallest()
,
getLargest()
,
getNotLarger(agents.context.Range)
,
AVLIntervalTree.Node.getPrevious()
,
AVLIntervalTree.Node.getNext()
public AVLIntervalTree.Node getNotLarger(Range reference)
reference
- reference object (may not be in the tree)getSmallest()
,
getLargest()
,
getNotSmaller(agents.context.Range)
,
AVLIntervalTree.Node.getPrevious()
,
AVLIntervalTree.Node.getNext()