E
- the wrapper type for this primitive typeT_ARR
- the array type for this primitive typeT_CONS
- the Consumer type for this primitive typepublic abstract static class SpinedBuffer.OfPrimitive<E,T_ARR,T_CONS> extends Object implements Iterable<E>
One or more arrays are used to store elements. The use of a multiple
arrays has better performance characteristics than a single array used by
ArrayList
, as when the capacity of the list needs to be increased
no copying of elements is required. This is usually beneficial in the case
where the results will be traversed a small number of times.
Modifier and Type | Field and Description |
---|---|
protected int |
elementIndex
Index of the *next* element to write; may point into, or just outside of,
the current chunk.
|
protected int |
initialChunkPower
log2 of the size of the first chunk.
|
static int |
MAX_CHUNK_POWER
Max power-of-two for chunks.
|
static int |
MIN_CHUNK_POWER
Minimum power-of-two for the first chunk.
|
static int |
MIN_CHUNK_SIZE
Minimum size for the first chunk.
|
static int |
MIN_SPINE_SIZE
Minimum array size for array-of-chunks.
|
protected long[] |
priorElementCount
Count of elements in all prior chunks.
|
protected int |
spineIndex
Index of the *current* chunk in the spine array, if the spine array is
non-null.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
arrayForEach(T_ARR array,
int from,
int to,
T_CONS consumer)
Iterate an array with the provided consumer
|
protected abstract int |
arrayLength(T_ARR array)
Get the length of an array
|
T_ARR |
asPrimitiveArray() |
protected long |
capacity() |
protected int |
chunkFor(long index) |
protected int |
chunkSize(int n)
How big should the nth chunk be?
|
void |
clear()
Remove all data from the buffer
|
void |
copyInto(T_ARR array,
int offset) |
long |
count()
How many elements are currently in the buffer?
|
protected void |
ensureCapacity(long targetSize) |
abstract void |
forEach(Consumer<? super E> consumer)
Performs the given action for each element of the
Iterable
until all elements have been processed or the action throws an
exception. |
void |
forEach(T_CONS consumer) |
protected void |
increaseCapacity() |
boolean |
isEmpty()
Is the buffer currently empty?
|
abstract Iterator<E> |
iterator()
Returns an iterator over elements of type
T . |
abstract T_ARR |
newArray(int size)
Create a new array of the proper type and size
|
protected abstract T_ARR[] |
newArrayArray(int size)
Create a new array-of-array of the proper type and size
|
protected void |
preAccept() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
spliterator
public static final int MIN_CHUNK_POWER
public static final int MIN_CHUNK_SIZE
public static final int MAX_CHUNK_POWER
public static final int MIN_SPINE_SIZE
protected final int initialChunkPower
protected int elementIndex
protected int spineIndex
protected long[] priorElementCount
public abstract Iterator<E> iterator()
Iterable
T
.public abstract void forEach(Consumer<? super E> consumer)
Iterable
Iterable
until all elements have been processed or the action throws an
exception. Unless otherwise specified by the implementing class,
actions are performed in the order of iteration (if an iteration order
is specified). Exceptions thrown by the action are relayed to the
caller.protected abstract T_ARR[] newArrayArray(int size)
public abstract T_ARR newArray(int size)
protected abstract int arrayLength(T_ARR array)
protected abstract void arrayForEach(T_ARR array, int from, int to, T_CONS consumer)
protected long capacity()
protected final void ensureCapacity(long targetSize)
protected void increaseCapacity()
protected int chunkFor(long index)
public void copyInto(T_ARR array, int offset)
public T_ARR asPrimitiveArray()
protected void preAccept()
public void clear()
public void forEach(T_CONS consumer)
public boolean isEmpty()
public long count()
protected int chunkSize(int n)