Class SortedViewIterator

  • Direct Known Subclasses:
    DoublesSortedViewIterator, FloatsSortedViewIterator, GenericSortedViewIterator

    public class SortedViewIterator
    extends Object
    This is the base interface for the SortedViewIterator hierarchy used with a SortedView obtained from a quantile-type sketch. This provides an ordered iterator over the retained quantiles of the associated quantile-type sketch.

    Prototype example of the recommended iteration loop:

    
       SortedViewIterator itr = sketch.getSortedView().iterator();
       while (itr.next()) {
         long weight = itr.getWeight();
         ...
       }
     
    Author:
    Alexander Saydakov, Lee Rhodes
    • Field Detail

      • cumWeights

        protected final long[] cumWeights
      • totalN

        protected long totalN
      • index

        protected int index
    • Method Detail

      • getNaturalRank

        public long getNaturalRank()
        Gets the natural rank at the current index. This is equivalent to getNaturalRank(INCLUSIVE).

        Don't call this before calling next() for the first time or after getting false from next().

        Returns:
        the natural rank at the current index.
      • getNaturalRank

        public long getNaturalRank​(QuantileSearchCriteria searchCrit)
        Gets the natural rank at the current index (or previous index) based on the chosen search criterion. This is also referred to as the "cumulative weight". The natural rank is a number in the range [1, N], where N (getN()) is the total number of items fed to the sketch.

        Don't call this before calling next() for the first time or after getting false from next().

        Parameters:
        searchCrit - if INCLUSIVE, includes the weight of the item at the current index in the computation of the natural rank. Otherwise, it will return the natural rank of the previous index.
        Returns:
        the natural rank at the current index (or previous index) based on the chosen search criterion.
      • getN

        public long getN()
        Gets the total count of all items presented to the sketch.
        Returns:
        the total count of all items presented to the sketch.
      • getNormalizedRank

        public double getNormalizedRank()
        Gets the normalized rank at the current index. This is equivalent to getNormalizedRank(INCLUSIVE).

        Don't call this before calling next() for the first time or after getting false from next().

        Returns:
        the normalized rank at the current index
      • getNormalizedRank

        public double getNormalizedRank​(QuantileSearchCriteria searchCrit)
        Gets the normalized rank at the current index (or previous index) based on the chosen search criterion. Where normalized rank = natural rank / N (getN()) and is a fraction in the range (0,1.0].

        Don't call this before calling next() for the first time or after getting false from next().

        Parameters:
        searchCrit - if INCLUSIVE, includes the normalized rank at the current index. Otherwise, returns the normalized rank of the previous index.
        Returns:
        the normalized rank at the current index (or previous index) based on the chosen search criterion.
      • getWeight

        public long getWeight()
        Gets the weight contribution of the item at the current index.

        Don't call this before calling next() for the first time or after getting false from next().

        Returns:
        the weight contribution of the item at the current index.
      • next

        public boolean next()
        Advances the index and checks if it is valid. The state of this iterator is undefined before the first call of this method.
        Returns:
        true if the next index is valid.