Class LongBigSpliterators.AbstractIndexBasedSpliterator

java.lang.Object
it.unimi.dsi.fastutil.longs.AbstractLongSpliterator
it.unimi.dsi.fastutil.longs.LongBigSpliterators.AbstractIndexBasedSpliterator
All Implemented Interfaces:
it.unimi.dsi.fastutil.longs.LongSpliterator, Spliterator<Long>, Spliterator.OfLong, Spliterator.OfPrimitive<Long,LongConsumer,Spliterator.OfLong>
Direct Known Subclasses:
LongBigSpliterators.EarlyBindingSizeIndexBasedSpliterator, LongBigSpliterators.LateBindingSizeIndexBasedSpliterator
Enclosing class:
LongBigSpliterators

public abstract static class LongBigSpliterators.AbstractIndexBasedSpliterator extends it.unimi.dsi.fastutil.longs.AbstractLongSpliterator
A skeletal implementation for a spliterator backed by an index based data store. High performance concrete implementations (like the main Spliterator of BigArrayBigList) generally should avoid using this and just implement the interface directly, but should be decent for less performance critical implementations.

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).

  • Field Details

    • pos

      protected long pos
      The current position index, the index of the item to be given after the next call to tryAdvance(java.util.function.LongConsumer).

      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.LongConsumer) 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 long get(long location)
      Get the item corresponding to the given index location.

      Do not advance pos in this method; the default tryAdvance(java.util.function.LongConsumer) and forEachRemaining(java.util.function.LongConsumer) 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.LongConsumer) was called twice and this method should return what the next call to

      invalid reference
      #tryAdvance()
      should give.
    • 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.LongConsumer) 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, LongBigSpliterators.EarlyBindingSizeIndexBasedSpliterator and LongBigSpliterators.LateBindingSizeIndexBasedSpliterator give an implementation of this method for the two most common strategies.

    • makeForSplit

      protected abstract it.unimi.dsi.fastutil.longs.LongSpliterator makeForSplit(long pos, long maxPos)
      Make a new spliterator to 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.

    • computeSplitPoint

      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).

      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.

    • characteristics

      public int characteristics()
    • estimateSize

      public long estimateSize()
    • tryAdvance

      public boolean tryAdvance(LongConsumer action)
    • forEachRemaining

      public void forEachRemaining(LongConsumer action)
    • skip

      public long skip(long n)
    • trySplit

      public it.unimi.dsi.fastutil.longs.LongSpliterator trySplit()
      Throws:
      IndexOutOfBoundsException - if the return of computeSplitPoint() was < pos or > {@link #getMaxPos()}.