Deprecated
as of 3.4, this class is not used anymore and considered to be out of scope of Apache Commons Math
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 |
|---|---|
| public class | AVLTree.
This class implements AVL trees nodes. |
| private static enum | AVLTree.
Enum for tree skew factor. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the element was deleted from the treeelement to delete (silently ignored if null) element)Delete an element from the tree. |
| public AVLTree | Returns: the tree node containing the largest element in the tree or null if the tree is emptyGet the node whose element is the largest one in the tree. |
| public AVLTree | Returns: the tree node containing the largest element not larger than the reference object (in which case the node is guaranteed not to be empty) or null if either the tree is empty or all its elements are larger than the reference objectreference object (may not be in the tree) reference)Get the node whose element is not larger than the reference object. |
| public AVLTree | Returns: the tree node containing the smallest element not smaller than the reference object or null if either the tree is empty or all its elements are smaller than the reference objectreference object (may not be in the tree) reference)Get the node whose element is not smaller than the reference object. |
| public AVLTree | Returns: the tree node containing the smallest element in the tree or null if the tree is emptyGet the node whose element is the smallest one in the tree. |
| public void | |
| public boolean | |
| public int |
| top | back to summary |
|---|---|
| private AVLTree<T>. Top level node. | |
| AVLTree | back to summary |
|---|---|
| public AVLTree() Build an empty tree. | |
| delete | back to summary |
|---|---|
| public boolean delete(final T element) Delete an element from the tree. The element is deleted only if there is a node
| |
| getLargest | back to summary |
|---|---|
| public AVLTree Get the node whose element is the largest one in the tree.
| |
| getNotLarger | back to summary |
|---|---|
| public AVLTree Get the node whose element is not larger than the reference object.
| |
| getNotSmaller | back to summary |
|---|---|
| public AVLTree Get the node whose element is not smaller than the reference object.
| |
| getSmallest | back to summary |
|---|---|
| public AVLTree Get the node whose element is the smallest one in the tree.
| |
| insert | back to summary |
|---|---|
| public void insert(final T element) Insert an element in the tree.
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Check if the tree is empty.
| |
| size | back to summary |
|---|---|
| public int size() Get the number of elements of the tree.
| |
AVL tree nodes implement all the logical structure of the
tree. Nodes are created by the AVLTree class.
The nodes are not independant from each other but must obey specific balancing constraints and the tree structure is rearranged as elements are inserted or deleted from the tree. The creation, modification and tree-related navigation methods have therefore restricted access. Only the order-related navigation, reading and delete methods are public.
AVLTree
| Modifier and Type | Field and Description |
|---|---|
| private T | element
Element contained in the current node. |
| private AVLTree | left
Left sub-tree. |
| private AVLTree | parent
Parent tree. |
| private AVLTree | right
Right sub-tree. |
| private AVLTree. | skew
Skew factor. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public T | |
| pack-priv AVLTree | Returns: the tree node containing the largest element in the tree rooted at this node or null if the tree is emptyGet the node whose element is the largest one in the tree rooted at this node. |
| public AVLTree | Returns: node containing the next larger or equal element (in which case the node is guaranteed not to be empty) or null if there is no larger or equal element in the treeGet the node containing the next larger or equal element. |
| public AVLTree | Returns: node containing the next smaller or equal element or null if there is no smaller or equal element in the treeGet the node containing the next smaller or equal element. |
| pack-priv AVLTree | Returns: the tree node containing the smallest element in the tree rooted at this node or null if the tree is emptyGet the node whose element is the smallest one in the tree rooted at this node. |
| pack-priv boolean | Returns: true if the parent tree should be re-Skew.BALANCEDelement to insert newElement)Insert an element in a sub-tree. |
| private boolean | Returns: true if the parent tree should be reSkew.BALANCED tooRe-balance the instance as left sub-tree has grown. |
| private boolean | Returns: true if the parent tree should be reSkew.BALANCED tooRe-balance the instance as left sub-tree has shrunk. |
| private boolean | Returns: true if the parent tree should be reSkew.BALANCED tooRe-balance the instance as right sub-tree has grown. |
| private boolean | Returns: true if the parent tree should be reSkew.BALANCED tooRe-balance the instance as right sub-tree has shrunk. |
| private void | |
| private void | |
| pack-priv int | Returns: number of elements contained in the tree rooted at this nodeGet the number of elements of the tree rooted at this node. |
| element | back to summary |
|---|---|
| private T element Element contained in the current node. | |
| left | back to summary |
|---|---|
| private AVLTree<T>. Left sub-tree. | |
| parent | back to summary |
|---|---|
| private AVLTree<T>. Parent tree. | |
| right | back to summary |
|---|---|
| private AVLTree<T>. Right sub-tree. | |
| skew | back to summary |
|---|---|
| private AVLTree. Skew factor. | |
| Node | back to summary |
|---|---|
| pack-priv Node(final T element, final AVLTree<T>. Build a node for a specified element. | |
| delete | back to summary |
|---|---|
| public void delete() Delete the node from the tree. | |
| getElement | back to summary |
|---|---|
| public T getElement() Get the contained element.
| |
| getLargest | back to summary |
|---|---|
| pack-priv AVLTree Get the node whose element is the largest one in the tree rooted at this node.
| |
| getNext | back to summary |
|---|---|
| public AVLTree Get the node containing the next larger or equal element.
| |
| getPrevious | back to summary |
|---|---|
| public AVLTree Get the node containing the next smaller or equal element. | |
| getSmallest | back to summary |
|---|---|
| pack-priv AVLTree Get the node whose element is the smallest one in the tree rooted at this node.
| |
| insert | back to summary |
|---|---|
| pack-priv boolean insert(final T newElement) Insert an element in a sub-tree.
| |
| rebalanceLeftGrown | back to summary |
|---|---|
| private boolean rebalanceLeftGrown() Re-balance the instance as left sub-tree has grown.
| |
| rebalanceLeftShrunk | back to summary |
|---|---|
| private boolean rebalanceLeftShrunk() Re-balance the instance as left sub-tree has shrunk.
| |
| rebalanceRightGrown | back to summary |
|---|---|
| private boolean rebalanceRightGrown() Re-balance the instance as right sub-tree has grown.
| |
| rebalanceRightShrunk | back to summary |
|---|---|
| private boolean rebalanceRightShrunk() Re-balance the instance as right sub-tree has shrunk.
| |
| rotateCCW | back to summary |
|---|---|
| private void rotateCCW() Perform a counter-clockwise rotation rooted at the instance. The skew factor are not updated by this method, they must be updated by the caller | |
| rotateCW | back to summary |
|---|---|
| private void rotateCW() Perform a clockwise rotation rooted at the instance. The skew factor are not updated by this method, they must be updated by the caller | |
| size | back to summary |
|---|---|
| pack-priv int size() Get the number of elements of the tree rooted at this node.
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final AVLTree. | BALANCED
Code for Skew.BALANCED trees. |
| public static final AVLTree. | LEFT_HIGH
Code for left high trees. |
| public static final AVLTree. | RIGHT_HIGH
Code for right high trees. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static AVLTree. | |
| public static AVLTree. |
| BALANCED | back to summary |
|---|---|
| public static final AVLTree. Code for Skew.BALANCED trees. | |
| LEFT_HIGH | back to summary |
|---|---|
| public static final AVLTree. Code for left high trees. | |
| RIGHT_HIGH | back to summary |
|---|---|
| public static final AVLTree. Code for right high trees. | |
| Skew | back to summary |
|---|---|
| private Skew() | |
| valueOf | back to summary |
|---|---|
| public static AVLTree. | |
| values | back to summary |
|---|---|
| public static AVLTree. | |