List implementation that is optimised for fast insertions and
removals at any index in the list.
This list implementation utilises a tree structure internally to ensure that
all insertions and removals are O(log n). This provides much faster performance
than both an ArrayList and a LinkedList where elements
are inserted and removed repeatedly from anywhere in the list.
The following relative performance statistics are indicative of this class:
get add insert iterate remove
TreeList 3 5 1 2 1
ArrayList 1 1 40 1 40
LinkedList 5800 1 350 2 325
ArrayList is a good general purpose list implementation.
It is faster than TreeList for most operations except inserting
and removing in the middle of the list. ArrayList also uses less
memory as TreeList uses one object per entry.
LinkedList is rarely a good choice of implementation.
TreeList is almost always a good replacement for it, although it
does use slightly more memory.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| private TreeList. | root
The root node in the AVL tree |
| private int | size
The current size of the list |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TreeList(final Collection<? extends E>
the collection to copy coll)Constructs a new empty list that copies the specified collection. |
| Modifier and Type | Method and Description |
|---|---|
| public void | add(final int
the index to add before index, final E the element to add obj)Overrides java. Implements java. |
| public boolean | Returns: true if this list changed as a result of the callthe collection to be added to this list c)Overrides java. Implements java. |
| private void | checkInterval(final int
the index to check index, final int the first allowed index startIndex, final int the last allowed index endIndex)Checks whether the index is valid. |
| public void | clear()
Overrides java. Implements java. |
| public boolean | Returns: true if the object is foundthe object to check object)Overrides java. Implements java. |
| public E | Returns: the element at the specified indexthe index to retrieve index)Implements abstract java. Implements java. |
| public int | Returns: the index of the object, -1 if not foundthe object to search object)Overrides java. Implements java. |
| public Iterator | Returns: an iterator over the listOverrides java. Implements java. |
| public ListIterator | Returns: the new iteratorOverrides java. Implements java. |
| public ListIterator | Returns: the new iteratorthe index to start from fromIndex)Overrides java. Implements java. |
| public E | Returns: the previous object at that indexthe index to remove index)Overrides java. Implements java. |
| public E | Returns: the previous object at that indexthe index to set index, final E the object to store at the specified index obj)Overrides java. Implements java. |
| public int | Returns: the current sizeImplements abstract java. Implements java. |
| public Object[] | Returns: the list as an arrayOverrides java. Implements java. |