Interface BatchIterator

All Superinterfaces:
Cloneable
All Known Implementing Classes:
RoaringBatchIterator, RoaringBatchIterator

public interface BatchIterator extends Cloneable
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advanceIfNeeded(int target)
    If needed, advance as long as the next value is smaller than minval The advanceIfNeeded method is used for performance reasons, to skip over unnecessary repeated calls to next.
    default IntIterator
    asIntIterator(int[] buffer)
    Creates a wrapper around the iterator so it behaves like an IntIterator
    Creates a copy of the iterator.
    boolean
    Returns true is there are more values to get.
    int
    nextBatch(int[] buffer)
    Writes the next batch of integers onto the buffer, and returns how many were written.
  • Method Details

    • nextBatch

      int nextBatch(int[] buffer)
      Writes the next batch of integers onto the buffer, and returns how many were written. Aims to fill the buffer.
      Parameters:
      buffer - - the target to write onto
      Returns:
      how many values were written during the call.
    • hasNext

      boolean hasNext()
      Returns true is there are more values to get.
      Returns:
      whether the iterator is exhaused or not.
    • clone

      BatchIterator clone()
      Creates a copy of the iterator.
      Returns:
      a clone of the current iterator
    • asIntIterator

      default IntIterator asIntIterator(int[] buffer)
      Creates a wrapper around the iterator so it behaves like an IntIterator
      Parameters:
      buffer - - array to buffer bits into (size 128-256 should be best).
      Returns:
      the wrapper
    • advanceIfNeeded

      void advanceIfNeeded(int target)
      If needed, advance as long as the next value is smaller than minval The advanceIfNeeded method is used for performance reasons, to skip over unnecessary repeated calls to next. Suppose for example that you wish to compute the intersection between an ordered list of integers (e.g., int[] x = {1,4,5}) and a BatchIterator. You might do it as follows...
      
           int[] buffer = new int[128];
           BatchIterator j = // get an iterator
           int val = // first value from my other data structure
           j.advanceIfNeeded(val);
           while ( j.hasNext() ) {
             int limit = j.nextBatch(buffer);
             for (int i = 0; i < limit; i++) {
               if (buffer[i] == val) {
                 // got it!
                 // do something here
                 val = // get next value?
               }
             }
             j.advanceIfNeeded(val);
           }
           
      The benefit of calling advanceIfNeeded is that each such call can be much faster than repeated calls to "next". The underlying implementation can "skip" over some data.
      Parameters:
      target - threshold