Class ObjectBigSpliterators.AbstractIndexBasedSpliterator<K>

java.lang.Object
it.unimi.dsi.fastutil.objects.AbstractObjectSpliterator<K>
it.unimi.dsi.fastutil.objects.ObjectBigSpliterators.AbstractIndexBasedSpliterator<K>
All Implemented Interfaces:
it.unimi.dsi.fastutil.objects.ObjectSpliterator<K>, Spliterator<K>
Direct Known Subclasses:
ObjectBigSpliterators.EarlyBindingSizeIndexBasedSpliterator, ObjectBigSpliterators.LateBindingSizeIndexBasedSpliterator
Enclosing class:
ObjectBigSpliterators

public abstract static class ObjectBigSpliterators.AbstractIndexBasedSpliterator<K> extends it.unimi.dsi.fastutil.objects.AbstractObjectSpliterator<K>
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

  • Constructor Details

    • AbstractIndexBasedSpliterator

      protected AbstractIndexBasedSpliterator(long initialPos)
  • Method Details

    • get

      protected abstract K 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.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

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

    • makeForSplit

      protected abstract it.unimi.dsi.fastutil.objects.ObjectSpliterator<K> 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(Consumer<? super K> action)
    • forEachRemaining

      public void forEachRemaining(Consumer<? super K> action)
    • skip

      public long skip(long n)
    • trySplit

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