public class SparseArray<T> extends Object implements Iterable<T>
An array/vector like data structure with a large capacity, that is a large maximum index, but that is expected to be mostly empty. For example, an array with space for one million elements but that will only ever contain a few hundred items.
This implementation uses two a data structures to provide the backing store
for the sparse array. A SkipList to provide efficient
linear access to the elements of the array, and a Hashtable
to provide efficient random access to the elements of the array.
NOTE: The iterator returned by a call to method iterator() iterates over the items present in the array and not the individual array elements. For example, the following only prints two items even though the array is 1,000 elements "long".
SparseArray array = new SparseArray();
array.setElementAt(0, "Hello");
arrar.setElementAt(999, "World");
for (String s : array)
{
System.out.println(s);
}
| Constructor and Description |
|---|
SparseArray() |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
T |
getElementAt(long index) |
long |
getMaxIndex() |
Iterator<T> |
iterator() |
static void |
main(String[] args) |
void |
setElementAt(long index,
T value) |
long |
size() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorCopyright © 2016 The American National Corpus. All rights reserved.