Class MaskedIntIterator

java.lang.Object
it.unimi.dsi.webgraph.MaskedIntIterator
All Implemented Interfaces:
LazyIntIterator

public class MaskedIntIterator
extends Object
implements LazyIntIterator
An iterator returning the element of an underlying iterator but filters them using a inclusion-exclusion block list.

A mask is an array of integers. The sum of the values contained in the mask must not exceed the number of elements returned by the underlying iterator. Moreover, all integers in the mask must be positive, except possibly for the first one, which may be zero.

Mask values are interpreted as specifying inclusion-exclusion blocks. Suppose that the underlying iterator returns N values, and that the mask is n0, n1, …, nk. Then, the first n0 values returned by the underlying iterator must be kept, the next n1 values must be ignored, the next n2 must be kept and so on. The last N−(n0+…+nk) must be kept if k is odd, and must be ignored otherwise. An instance of this class will returns the kept values only, in increasing order.

  • Constructor Summary

    Constructors
    Constructor Description
    MaskedIntIterator​(int[] mask, int maskLen, LazyIntIterator underlying)
    Creates a new masked iterator using a given mask, mask length and underlying iterator.
    MaskedIntIterator​(int[] mask, LazyIntIterator underlying)
    Creates a new masked iterator using a given mask and underlying iterator.
  • Method Summary

    Modifier and Type Method Description
    int nextInt()
    The next integer returned by this iterator, or the special marker if this iterator is exhausted.
    int skip​(int n)
    Skips a given number of elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MaskedIntIterator

      public MaskedIntIterator​(int[] mask, LazyIntIterator underlying)
      Creates a new masked iterator using a given mask and underlying iterator.
      Parameters:
      mask - a mask, or null, meaning an empty mask (everything is copied).
      underlying - an underlying iterator.
    • MaskedIntIterator

      public MaskedIntIterator​(int[] mask, int maskLen, LazyIntIterator underlying)
      Creates a new masked iterator using a given mask, mask length and underlying iterator.
      Parameters:
      mask - a mask, or null, meaning an empty mask (everything is copied).
      maskLen - an explicit mask length.
      underlying - an underlying iterator.
  • Method Details

    • nextInt

      public int nextInt()
      Description copied from interface: LazyIntIterator
      The next integer returned by this iterator, or the special marker if this iterator is exhausted.
      Specified by:
      nextInt in interface LazyIntIterator
      Returns:
      next integer returned by this iterator, or the special marker if this iterator is exhausted.
    • skip

      public int skip​(int n)
      Description copied from interface: LazyIntIterator
      Skips a given number of elements.
      Specified by:
      skip in interface LazyIntIterator
      Parameters:
      n - the number of elements to skip.
      Returns:
      the number of elements actually skipped (which might be less than n if this iterator is exhausted).