public class RangeList<E>
extends java.lang.Object
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 |
|---|---|
static class |
RangeList.AVLNode<E>
Implements an AVLNode which keeps the offset updated.
|
| Modifier and Type | Field and Description |
|---|---|
RangeList.AVLNode<E> |
root
The root node in the AVL tree
|
| Constructor and Description |
|---|
RangeList()
Constructs a new empty list.
|
RangeList(java.util.Collection<? extends E> coll)
Constructs a new empty list that copies the specified collection.
|
| Modifier and Type | Method and Description |
|---|---|
RangeList.AVLNode<E> |
access(int index,
int modify,
int[] endIndex) |
void |
add(int index,
E obj)
Adds a new element to the list.
|
void |
clear()
Clears the list, removing all entries.
|
RangeList.AVLNode<E> |
getIn(int index,
int[] endIndex)
Gets the element at the specified index.
|
void |
remove(int index)
Removes the element at the specified index.
|
int |
size()
Gets the current size of the list.
|
java.lang.Object[] |
toArray()
Converts the list into an array.
|
public RangeList.AVLNode<E> root
public RangeList()
public RangeList(java.util.Collection<? extends E> coll)
coll - the collection to copyjava.lang.NullPointerException - if the collection is nullpublic RangeList.AVLNode<E> getIn(int index, int[] endIndex)
index - the index to retrievepublic RangeList.AVLNode<E> access(int index, int modify, int[] endIndex)
public int size()
public java.lang.Object[] toArray()
public void add(int index,
E obj)
index - the index to add beforeobj - the element to addpublic void remove(int index)
index - the index to removepublic void clear()