public abstract static class ObjectBigSpliterators.AbstractIndexBasedSpliterator<K>
extends it.unimi.dsi.fastutil.objects.AbstractObjectSpliterator<K>
As the abstract methods in this class are used in inner loops, it is generally a
good idea to override the class as final as to encourage the JVM to inline
them (or alternatively, override the abstract methods as final).
| Modifier and Type | Field and Description |
|---|---|
protected long |
pos
The current position index, the index of the item to be given after the next call to
tryAdvance(java.util.function.Consumer<? super K>). |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractIndexBasedSpliterator(long initialPos) |
| Modifier and Type | Method and Description |
|---|---|
int |
characteristics() |
protected long |
computeSplitPoint()
Compute where to split on the next
trySplit(), given the current pos and
getMaxPos() (or any other metric the implementation wishes to use). |
long |
estimateSize() |
void |
forEachRemaining(java.util.function.Consumer<? super K> action) |
protected abstract K |
get(long location)
Get the item corresponding to the given index location.
|
protected abstract long |
getMaxPos()
The maximum pos can be, and is the logical end (exclusive) of the "range".
|
protected abstract it.unimi.dsi.fastutil.objects.ObjectSpliterator<K> |
makeForSplit(long pos,
long maxPos)
|
long |
skip(long n) |
boolean |
tryAdvance(java.util.function.Consumer<? super K> action) |
it.unimi.dsi.fastutil.objects.ObjectSpliterator<K> |
trySplit() |
protected long pos
tryAdvance(java.util.function.Consumer<? super K>).
This value will be between minPos and getMaxPos() (exclusive) (on a best effort, so concurrent
structural modifications may cause this to be violated, but that usually invalidates spliterators anyways).
Thus pos being minPos + 2 would mean tryAdvance(java.util.function.Consumer<? super K>)
was called twice and the next call will give the third element of this spliterator.
protected AbstractIndexBasedSpliterator(long initialPos)
protected abstract K get(long location)
Do not advance pos in this method; the default tryAdvance(java.util.function.Consumer<? super K>) and
forEachRemaining(java.util.function.Consumer<? super K>) methods takes care of this.
The location given will be between minPos and getMaxPos() (exclusive).
Thus, a location of minPos + 2 would mean tryAdvance(java.util.function.Consumer<? super K>) was called twice
and this method should return what the next call to #tryAdvance() should give.
protected abstract long getMaxPos()
If pos is equal to the return of this method, this means the last element has been returned and the next call to tryAdvance(java.util.function.Consumer<? super K>) will return false.
Usually set return the parent collection's size, but does not have to be (for example, sublists and subranges).
This method allows the implementation to decide how it binds on the size (late or early).
However, ObjectBigSpliterators.EarlyBindingSizeIndexBasedSpliterator and ObjectBigSpliterators.LateBindingSizeIndexBasedSpliterator give
an implementation of this method for the two most common strategies.
protected abstract it.unimi.dsi.fastutil.objects.ObjectSpliterator<K> makeForSplit(long pos, long maxPos)
trySplit() starting with the given pos
and ending at the given maxPos.
An implementation is free to look at the range given, and if it deems it too small
to split further, return null. In which case, trySplit() will not
modify the state of this spliterator.
Do not modify pos in this method; the default trySplit()
method takes care of this.
To comply with the spec of Spliterator.ORDERED, this will
only be called to create prefixes of the current sequence this spliterator is over,
and this instance will start at the end of the returned sequence and have the same
end point.
As such, this method should also not change what getMaxPos() returns.
protected long computeSplitPoint()
trySplit(), given the current pos and
getMaxPos() (or any other metric the implementation wishes to use).
If a value == pos or == getMaxPos() is returned, the
trySplit() method will assume a split of size 0 was computed,
and thus won't split or change state. If a value outside that range is
returned, then trySplit() will throw IndexOutOfBoundsException.
In particular, this means that no handling of overflow or underflow
is performed.
public int characteristics()
public long estimateSize()
public boolean tryAdvance(java.util.function.Consumer<? super K> action)
public void forEachRemaining(java.util.function.Consumer<? super K> action)
public long skip(long n)
public it.unimi.dsi.fastutil.objects.ObjectSpliterator<K> trySplit()
java.lang.IndexOutOfBoundsException - if the return of computeSplitPoint() was
< pos or > {@link #getMaxPos()}.