Class CompressedExponentialHistogram
java.lang.Object
org.elasticsearch.exponentialhistogram.AbstractExponentialHistogram
org.elasticsearch.exponentialhistogram.CompressedExponentialHistogram
- All Implemented Interfaces:
org.apache.lucene.util.Accountable,ExponentialHistogram
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.
-
Field Summary
Fields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLEFields inherited from interface org.elasticsearch.exponentialhistogram.ExponentialHistogram
MAX_INDEX, MAX_INDEX_BITS, MAX_SCALE, MIN_INDEX, MIN_SCALE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublemax()Returns maximum of all values represented by this histogram.doublemin()Returns minimum of all values represented by this histogram.longvoidreset(double zeroThreshold, long valueCount, double sum, double min, double max, org.apache.lucene.util.BytesRef encodedHistogramData) Resets this instance to decode the provided histogram data.intscale()The scale of the histogram.doublesum()Returns the sum of all values represented by this histogram.longReturns the number of values represented by this histogram.static voidwriteHistogramBytes(OutputStream output, int scale, BucketIterator negativeBuckets, BucketIterator positiveBuckets) Serializes the given histogram, so that exactly the same data can be reconstructed viareset(double, long, double, double, double, BytesRef).Methods inherited from class org.elasticsearch.exponentialhistogram.AbstractExponentialHistogram
equals, hashCode, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.lucene.util.Accountable
getChildResources
-
Constructor Details
-
CompressedExponentialHistogram
public CompressedExponentialHistogram()
-
-
Method Details
-
scale
public int scale()Description copied from interface:ExponentialHistogramThe scale of the histogram. Higher scales result in higher accuracy but potentially more buckets. Must be less than or equal toExponentialHistogram.MAX_SCALEand greater than or equal toExponentialHistogram.MIN_SCALE.- Returns:
- the scale of the histogram
-
zeroBucket
- Returns:
- the
ZeroBucketrepresenting the number of zero (or close-to-zero) values and its threshold
-
sum
public double sum()Description copied from interface:ExponentialHistogramReturns 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:ExponentialHistogramReturns 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:
valueCountin interfaceExponentialHistogram- Overrides:
valueCountin classAbstractExponentialHistogram- Returns:
- the value count, guaranteed to be zero for empty histograms
-
min
public double min()Description copied from interface:ExponentialHistogramReturns minimum of all values represented by this histogram.- Returns:
- the minimum, NaN for empty histograms
-
max
public double max()Description copied from interface:ExponentialHistogramReturns maximum of all values represented by this histogram.- Returns:
- the maximum, NaN for empty histograms
-
positiveBuckets
- Returns:
- a
ExponentialHistogram.Bucketsinstance for the populated buckets covering the positive value range of this histogram. TheBucketIterator.scale()of iterators obtained viaExponentialHistogram.Buckets.iterator()must be the same asExponentialHistogram.scale().
-
negativeBuckets
- Returns:
- a
ExponentialHistogram.Bucketsinstance for the populated buckets covering the negative value range of this histogram. TheBucketIterator.scale()of iterators obtained viaExponentialHistogram.Buckets.iterator()must be the same asExponentialHistogram.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 externallyvalueCount- the total number of values the histogram contains, needs to be stored externallysum- the total sum of the values the histogram contains, needs to be stored externallymin- the minimum of the values the histogram contains, needs to be stored externally. Must beDouble.NaNif the histogram is empty, non-Nan otherwise.max- the maximum of the values the histogram contains, needs to be stored externally. Must beDouble.NaNif the histogram is empty, non-Nan otherwise.encodedHistogramData- the encoded histogram bytes which previously where generated viawriteHistogramBytes(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 viareset(double, long, double, double, double, BytesRef).- Parameters:
output- the output to write the serialized bytes toscale- the scale of the histogramnegativeBuckets- the negative buckets of the histogram, sorted by the bucket indicespositiveBuckets- the positive buckets of the histogram, sorted by the bucket indices- Throws:
IOException
-
ramBytesUsed
public long ramBytesUsed()
-