Unlike java., this type does not need to reallocate the
internal array in order to expand the capacity of the list. Access to any
element is constant time, but requires two array lookups instead of one.
To handle common usages, add(Object) and iterator() use
internal code paths to amortize out the second array lookup, making addition
and simple iteration closer to one array operation per element processed.
Similar to ArrayList, adding or removing from any position except the
end of the list requires O(N) time to copy all elements between the
modification point and the end of the list. Applications are strongly
encouraged to not use this access pattern with this list implementation.
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private static final int | |
| private static final int | |
| pack-priv static final int | |
| pack-priv T[][] | |
| pack-priv int | |
| private int | |
| private T[] | |
| private int |
| Access | Constructor and Description |
|---|---|
| public | |
| public | BlockList(int
number of elements expected to be in the list. capacity)Initialize an empty list with an expected capacity. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(T
element to be appended to this list element)Overrides java. Implements java. Appends the specified element to the end of this list (optional operation). |
| public void | add(int
index at which the specified element is to be inserted index, T element to be inserted element)Overrides java. Implements java. Inserts the specified element at the specified position in this list (optional operation). |
| public void | |
| public void | addAll(T[]
the source array. src, int first index to copy. srcIdx, int number of elements to copy. srcCnt)Quickly append all elements from an array. |
| public void | clear()
Overrides java. Implements java. Removes all of the elements from this list (optional operation). |
| public T | get(int
index of the element to return index)Implements abstract java. Implements java. Returns the element at the specified position in this list. |
| public Iterator | iterator()
Overrides java. Implements java. Returns an iterator over the elements in this list in proper sequence. |
| private static <T> T[] | |
| private static <T> T[][] | |
| public T | remove(int
the index of the element to be removed index)Overrides java. Implements java. Removes the element at the specified position in this list (optional operation). |
| private void | |
| public T | set(int
index of the element to replace index, T element to be stored at the specified position element)Overrides java. Implements java. Replaces the element at the specified position in this list with the specified element (optional operation). |
| public int | size()
Implements abstract java. Implements java. Returns the number of elements in this list. |
| pack-priv static final int | |
| pack-priv static final int |
| BLOCK_BITS | back to summary |
|---|---|
| private static final int BLOCK_BITS | |
| BLOCK_MASK | back to summary |
|---|---|
| private static final int BLOCK_MASK | |
| BLOCK_SIZE | back to summary |
|---|---|
| pack-priv static final int BLOCK_SIZE | |
| directory | back to summary |
|---|---|
| pack-priv T[][] directory | |
| size | back to summary |
|---|---|
| pack-priv int size | |
| tailBlkIdx | back to summary |
|---|---|
| private int tailBlkIdx | |
| tailBlock | back to summary |
|---|---|
| private T[] tailBlock | |
| tailDirIdx | back to summary |
|---|---|
| private int tailDirIdx | |
| BlockList | back to summary |
|---|---|
| public BlockList() Initialize an empty list. | |
| BlockList | back to summary |
|---|---|
| public BlockList(int capacity) Initialize an empty list with an expected capacity.
| |
| add | back to summary |
|---|---|
| public boolean add(T element) Overrides java. Implements java. Doc from java. Appends the specified element to the end of this list (optional operation). Lists that support this operation may place limitations on what elements may be added to this list. In particular, some lists will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. List classes should clearly specify in their documentation any restrictions on what elements may be added.
| |
| add | back to summary |
|---|---|
| public void add(int index, T element) Overrides java. Implements java. Doc from java. Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).
| |
| addAll | back to summary |
|---|---|
| public void addAll(BlockList<T> src) Quickly append all elements of another BlockList.
| |
| addAll | back to summary |
|---|---|
| public void addAll(T[] src, int srcIdx, int srcCnt) Quickly append all elements from an array.
| |
| clear | back to summary |
|---|---|
| public void clear() Overrides java. Implements java. Doc from java. Removes all of the elements from this list (optional operation). The list will be empty after this call returns.
| |
| get | back to summary |
|---|---|
| public T get(int index) Implements abstract java. Implements java. Doc from java. Returns the element at the specified position in this list.
| |
| iterator | back to summary |
|---|---|
| public Iterator Overrides java. Implements java. Doc from java. Returns an iterator over the elements in this list in proper sequence. | |
| newBlock | back to summary |
|---|---|
private static <T> T[] newBlock()
| |
| newDirectory | back to summary |
|---|---|
private static <T> T[][] newDirectory(int size)
| |
| remove | back to summary |
|---|---|
| public T remove(int index) Overrides java. Implements java. Doc from java. Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.
| |
| resetTailBlock | back to summary |
|---|---|
| private void resetTailBlock() | |
| set | back to summary |
|---|---|
| public T set(int index, T element) Overrides java. Implements java. Doc from java. Replaces the element at the specified position in this list with the specified element (optional operation).
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this list. If this list contains
more than
| |
| toBlockIndex | back to summary |
|---|---|
| pack-priv static final int toBlockIndex(int index) | |
| toDirectoryIndex | back to summary |
|---|---|
| pack-priv static final int toDirectoryIndex(int index) | |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private T[] | |
| private int | |
| private int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public T | |
| public void | remove()
Overrides default java. Removes from the underlying collection the last element returned by this iterator (optional operation). |
| blkIdx | back to summary |
|---|---|
| private int blkIdx | |
| block | back to summary |
|---|---|
| private T[] block | |
| dirIdx | back to summary |
|---|---|
| private int dirIdx | |
| index | back to summary |
|---|---|
| private int index | |
| MyIterator | back to summary |
|---|---|
| private MyIterator() | |
| hasNext | back to summary |
|---|---|
| public boolean hasNext() Implements java. Doc from java. Returns
| |
| next | back to summary |
|---|---|
| public T next() Implements java. Doc from java. Returns the next element in the iteration.
| |
| remove | back to summary |
|---|---|
| public void remove() Overrides default java. Doc from java. Removes from the underlying collection the last element returned
by this iterator (optional operation). This method can be called
only once per call to The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.
The behavior of an iterator is unspecified if this method is called
after a call to the
| |