Class IntBigSpliterators.AbstractIndexBasedSpliterator
- All Implemented Interfaces:
it.unimi.dsi.fastutil.ints.IntSpliterator,Spliterator<Integer>,Spliterator.OfInt,Spliterator.OfPrimitive<Integer,IntConsumer, Spliterator.OfInt>
- Direct Known Subclasses:
IntBigSpliterators.EarlyBindingSizeIndexBasedSpliterator,IntBigSpliterators.LateBindingSizeIndexBasedSpliterator
- Enclosing class:
IntBigSpliterators
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).
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T,T_CONS, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected longThe current position index, the index of the item to be given after the next call totryAdvance(java.util.function.IntConsumer).Fields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintprotected longCompute where to split on the nexttrySplit(), given the current pos andgetMaxPos()(or any other metric the implementation wishes to use).longvoidforEachRemaining(IntConsumer action) protected abstract intget(long location) Get the item corresponding to the given index location.protected abstract longThe maximum pos can be, and is the logical end (exclusive) of the "range".protected abstract it.unimi.dsi.fastutil.ints.IntSpliteratormakeForSplit(long pos, long maxPos) longskip(long n) booleantryAdvance(IntConsumer action) it.unimi.dsi.fastutil.ints.IntSpliteratortrySplit()Methods inherited from class it.unimi.dsi.fastutil.ints.AbstractIntSpliterator
forEachRemaining, tryAdvanceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface it.unimi.dsi.fastutil.ints.IntSpliterator
forEachRemaining, getComparator, tryAdvanceMethods inherited from interface java.util.Spliterator
getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
pos
protected long posThe current position index, the index of the item to be given after the next call totryAdvance(java.util.function.IntConsumer).This value will be between
minPosandgetMaxPos()(exclusive) (on a best effort, so concurrent structural modifications may cause this to be violated, but that usually invalidates spliterators anyways). ThusposbeingminPos + 2would meantryAdvance(java.util.function.IntConsumer)was called twice and the next call will give the third element of this spliterator.
-
-
Constructor Details
-
AbstractIndexBasedSpliterator
protected AbstractIndexBasedSpliterator(long initialPos)
-
-
Method Details
-
get
protected abstract int get(long location) Get the item corresponding to the given index location.Do not advance
posin this method; the defaulttryAdvance(java.util.function.IntConsumer)andforEachRemaining(java.util.function.IntConsumer)methods takes care of this.The
locationgiven will be betweenminPosandgetMaxPos()(exclusive). Thus, alocationofminPos + 2would meantryAdvance(java.util.function.IntConsumer)was called twice and this method should return what the next call toshould give.invalid reference
#tryAdvance() -
getMaxPos
protected abstract long getMaxPos()The maximum pos can be, and is the logical end (exclusive) of the "range".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.IntConsumer)will returnfalse.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,
IntBigSpliterators.EarlyBindingSizeIndexBasedSpliteratorandIntBigSpliterators.LateBindingSizeIndexBasedSpliteratorgive an implementation of this method for the two most common strategies. -
makeForSplit
protected abstract it.unimi.dsi.fastutil.ints.IntSpliterator makeForSplit(long pos, long maxPos) Make a new spliterator totrySplit()starting with the givenposand ending at the givenmaxPos.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
posin this method; the defaulttrySplit()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 whatgetMaxPos()returns. -
computeSplitPoint
protected long computeSplitPoint()Compute where to split on the nexttrySplit(), given the current pos andgetMaxPos()(or any other metric the implementation wishes to use).If a value
== posor== getMaxPos()is returned, thetrySplit()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, thentrySplit()will throwIndexOutOfBoundsException. In particular, this means that no handling of overflow or underflow is performed. -
characteristics
public int characteristics() -
estimateSize
public long estimateSize() -
tryAdvance
-
forEachRemaining
-
skip
public long skip(long n) -
trySplit
public it.unimi.dsi.fastutil.ints.IntSpliterator trySplit()- Throws:
IndexOutOfBoundsException- if the return ofcomputeSplitPoint()was< posor> {@link #getMaxPos()}.
-