Class MaskedLongIterator

java.lang.Object
it.unimi.dsi.big.webgraph.MaskedLongIterator
All Implemented Interfaces:
LazyLongIterator

public class MaskedLongIterator extends Object implements LazyLongIterator
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 Details

    • MaskedLongIterator

      public MaskedLongIterator(long[] mask, LazyLongIterator 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.
    • MaskedLongIterator

      public MaskedLongIterator(long[] mask, int maskLen, LazyLongIterator 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

    • nextLong

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

      public long skip(long n)
      Description copied from interface: LazyLongIterator
      Skips a given number of elements.
      Specified by:
      skip in interface LazyLongIterator
      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).