Class CompressedExponentialHistogram

java.lang.Object
org.elasticsearch.exponentialhistogram.AbstractExponentialHistogram
org.elasticsearch.exponentialhistogram.CompressedExponentialHistogram
All Implemented Interfaces:
org.apache.lucene.util.Accountable, ExponentialHistogram

public class CompressedExponentialHistogram extends AbstractExponentialHistogram
Implementation of a ExponentialHistogram optimized for a minimal memory footprint.

While this implementation is optimized for a minimal memory footprint, it is still a fully compliant ExponentialHistogram and can therefore be directly consumed for merging / quantile estimation without requiring any prior copying or decoding. Note that this histogram implementation stores the zero threshold as double value. For that reason it is lossy if used for storing intermediate merge results, which can have the zero threshold represented as a (scale, index) pair.

  • Constructor Details

    • CompressedExponentialHistogram

      public CompressedExponentialHistogram()
  • Method Details

    • scale

      public int scale()
      Description copied from interface: ExponentialHistogram
      The scale of the histogram. Higher scales result in higher accuracy but potentially more buckets. Must be less than or equal to ExponentialHistogram.MAX_SCALE and greater than or equal to ExponentialHistogram.MIN_SCALE.
      Returns:
      the scale of the histogram
    • zeroBucket

      public ZeroBucket zeroBucket()
      Returns:
      the ZeroBucket representing the number of zero (or close-to-zero) values and its threshold
    • sum

      public double sum()
      Description copied from interface: ExponentialHistogram
      Returns the sum of all values represented by this histogram. Note that even if histograms are cumulative, the sum is not guaranteed to be monotonically increasing, because histograms support negative values.
      Returns:
      the sum, guaranteed to be zero for empty histograms
    • valueCount

      public long valueCount()
      Description copied from interface: ExponentialHistogram
      Returns the number of values represented by this histogram. In other words, this is the sum of the counts of all buckets including the zero bucket.
      Specified by:
      valueCount in interface ExponentialHistogram
      Overrides:
      valueCount in class AbstractExponentialHistogram
      Returns:
      the value count, guaranteed to be zero for empty histograms
    • min

      public double min()
      Description copied from interface: ExponentialHistogram
      Returns minimum of all values represented by this histogram.
      Returns:
      the minimum, NaN for empty histograms
    • max

      public double max()
      Description copied from interface: ExponentialHistogram
      Returns maximum of all values represented by this histogram.
      Returns:
      the maximum, NaN for empty histograms
    • positiveBuckets

      public ExponentialHistogram.Buckets positiveBuckets()
      Returns:
      a ExponentialHistogram.Buckets instance for the populated buckets covering the positive value range of this histogram. The BucketIterator.scale() of iterators obtained via ExponentialHistogram.Buckets.iterator() must be the same as ExponentialHistogram.scale().
    • negativeBuckets

      public ExponentialHistogram.Buckets negativeBuckets()
      Returns:
      a ExponentialHistogram.Buckets instance for the populated buckets covering the negative value range of this histogram. The BucketIterator.scale() of iterators obtained via ExponentialHistogram.Buckets.iterator() must be the same as ExponentialHistogram.scale().
    • reset

      public void reset(double zeroThreshold, long valueCount, double sum, double min, double max, org.apache.lucene.util.BytesRef encodedHistogramData) throws IOException
      Resets this instance to decode the provided histogram data.
      Parameters:
      zeroThreshold - the zeroThreshold for the histogram, which needs to be stored externally
      valueCount - the total number of values the histogram contains, needs to be stored externally
      sum - the total sum of the values the histogram contains, needs to be stored externally
      min - the minimum of the values the histogram contains, needs to be stored externally. Must be Double.NaN if the histogram is empty, non-Nan otherwise.
      max - the maximum of the values the histogram contains, needs to be stored externally. Must be Double.NaN if the histogram is empty, non-Nan otherwise.
      encodedHistogramData - the encoded histogram bytes which previously where generated via writeHistogramBytes(OutputStream, int, BucketIterator, BucketIterator).
      Throws:
      IOException
    • writeHistogramBytes

      public static void writeHistogramBytes(OutputStream output, int scale, BucketIterator negativeBuckets, BucketIterator positiveBuckets) throws IOException
      Serializes the given histogram, so that exactly the same data can be reconstructed via reset(double, long, double, double, double, BytesRef).
      Parameters:
      output - the output to write the serialized bytes to
      scale - the scale of the histogram
      negativeBuckets - the negative buckets of the histogram, sorted by the bucket indices
      positiveBuckets - the positive buckets of the histogram, sorted by the bucket indices
      Throws:
      IOException
    • ramBytesUsed

      public long ramBytesUsed()