Interface ExponentialHistogram
- All Superinterfaces:
org.apache.lucene.util.Accountable
- All Known Subinterfaces:
ReleasableExponentialHistogram
- All Known Implementing Classes:
AbstractExponentialHistogram,CompressedExponentialHistogram
public interface ExponentialHistogram
extends org.apache.lucene.util.Accountable
Interface for implementations of exponential histograms adhering to the
OpenTelemetry definition.
This interface supports sparse implementations, allowing iteration over buckets without requiring direct index access.
The most important properties are:
Additionally, all algorithms assume that samples within a bucket are located at a single point: the point of least relative error (see
The most important properties are:
- The histogram has a scale parameter, which defines the accuracy. A higher scale implies a higher accuracy.
The
basefor the buckets is defined asbase = 2^(2^-scale). - The histogram bucket at index
ihas the range(base^i, base^(i+1)] - Negative values are represented by a separate negative range of buckets with the boundaries
(-base^(i+1), -base^i] - Histograms are perfectly subsetting: increasing the scale by one merges each pair of neighboring buckets
- A special
ZeroBucketis used to handle zero and close-to-zero values
Additionally, all algorithms assume that samples within a bucket are located at a single point: the point of least relative error (see
ExponentialScaleUtils.getPointOfLeastRelativeError(long, int)).-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents a bucket range of anExponentialHistogram, either the positive or the negative range. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final intstatic final intstatic final longstatic final intFields inherited from interface org.apache.lucene.util.Accountable
NULL_ACCOUNTABLE -
Method Summary
Modifier and TypeMethodDescriptionstatic ExponentialHistogramBuilderbuilder(int scale, ExponentialHistogramCircuitBreaker breaker) Create a builder for an exponential histogram with the given scale.static ExponentialHistogramBuilderbuilder(ExponentialHistogram toCopy, ExponentialHistogramCircuitBreaker breaker) Create a builder for an exponential histogram, which is initialized to copy the given histogram.create(int maxBucketCount, ExponentialHistogramCircuitBreaker breaker, double... values) Creates a histogram representing the distribution of the given values with at most the given number of buckets.static ExponentialHistogramempty()static booleanValue-based equality for exponential histograms.static inthashCode(ExponentialHistogram histogram) Default hash code implementation to be used withequals(ExponentialHistogram, ExponentialHistogram).doublemax()Returns maximum of all values represented by this histogram.merge(int maxBucketCount, ExponentialHistogramCircuitBreaker breaker, Iterator<? extends ExponentialHistogram> histograms) Merges the provided exponential histograms to a new, single histogram with at most the given amount of buckets.merge(int maxBucketCount, ExponentialHistogramCircuitBreaker breaker, ExponentialHistogram... histograms) Merges the provided exponential histograms to a new, single histogram with at most the given amount of buckets.doublemin()Returns minimum of all values represented by this histogram.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.Methods inherited from interface org.apache.lucene.util.Accountable
getChildResources, ramBytesUsed
-
Field Details
-
MAX_SCALE
static final int MAX_SCALE- See Also:
-
MIN_SCALE
static final int MIN_SCALE- See Also:
-
MAX_INDEX_BITS
static final int MAX_INDEX_BITS- See Also:
-
MAX_INDEX
static final long MAX_INDEX- See Also:
-
MIN_INDEX
static final long MIN_INDEX- See Also:
-
-
Method Details
-
scale
int scale()The scale of the histogram. Higher scales result in higher accuracy but potentially more buckets. Must be less than or equal toMAX_SCALEand greater than or equal toMIN_SCALE.- Returns:
- the scale of the histogram
-
zeroBucket
ZeroBucket zeroBucket()- Returns:
- the
ZeroBucketrepresenting the number of zero (or close-to-zero) values and its threshold
-
positiveBuckets
ExponentialHistogram.Buckets 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 asscale().
-
negativeBuckets
ExponentialHistogram.Buckets 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 asscale().
-
sum
double sum()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
long valueCount()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.- Returns:
- the value count, guaranteed to be zero for empty histograms
-
min
double min()Returns minimum of all values represented by this histogram.- Returns:
- the minimum, NaN for empty histograms
-
max
double max()Returns maximum of all values represented by this histogram.- Returns:
- the maximum, NaN for empty histograms
-
equals
Value-based equality for exponential histograms.- Parameters:
a- the first histogram (can be null)b- the second histogram (can be null)- Returns:
- true, if both histograms are equal
-
hashCode
Default hash code implementation to be used withequals(ExponentialHistogram, ExponentialHistogram).- Parameters:
histogram- the histogram to hash- Returns:
- the hash code
-
empty
-
builder
Create a builder for an exponential histogram with the given scale.- Parameters:
scale- the scale of the histogram to buildbreaker- the circuit breaker to use- Returns:
- a new builder
-
builder
static ExponentialHistogramBuilder builder(ExponentialHistogram toCopy, ExponentialHistogramCircuitBreaker breaker) Create a builder for an exponential histogram, which is initialized to copy the given histogram.- Parameters:
toCopy- the histogram to copybreaker- the circuit breaker to use- Returns:
- a new builder
-
create
static ReleasableExponentialHistogram create(int maxBucketCount, ExponentialHistogramCircuitBreaker breaker, double... values) Creates a histogram representing the distribution of the given values with at most the given number of buckets. If the givenmaxBucketCountis greater than or equal to the number of values, the resulting histogram will have a relative error of less than2^(2^-MAX_SCALE) - 1.- Parameters:
maxBucketCount- the maximum number of bucketsbreaker- the circuit breaker to use to limit memory allocationsvalues- the values to be added to the histogram- Returns:
- a new
ReleasableExponentialHistogram
-
merge
static ReleasableExponentialHistogram merge(int maxBucketCount, ExponentialHistogramCircuitBreaker breaker, Iterator<? extends ExponentialHistogram> histograms) Merges the provided exponential histograms to a new, single histogram with at most the given amount of buckets.- Parameters:
maxBucketCount- the maximum number of buckets the result histogram is allowed to havebreaker- the circuit breaker to use to limit memory allocationshistograms- the histograms to merge- Returns:
- the merged histogram
-
merge
static ReleasableExponentialHistogram merge(int maxBucketCount, ExponentialHistogramCircuitBreaker breaker, ExponentialHistogram... histograms) Merges the provided exponential histograms to a new, single histogram with at most the given amount of buckets.- Parameters:
maxBucketCount- the maximum number of buckets the result histogram is allowed to havebreaker- the circuit breaker to use to limit memory allocationshistograms- the histograms to merge- Returns:
- the merged histogram
-