Class ExponentialScaleUtils
java.lang.Object
org.elasticsearch.exponentialhistogram.ExponentialScaleUtils
A collection of utility methods for working with indices and scales of exponential bucket histograms.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompareExponentiallyScaledValues(long idxA, int scaleA, long idxB, int scaleB) Compares the lower boundaries of two buckets, which may have different scales.static longcomputeIndex(double value, int scale) Provides the index of the bucket of the exponential histogram with the given scale that contains the provided value.static doublegetLowerBucketBoundary(long index, int scale) Returns the lower boundary of the bucket with the given index and scale.static doublegetPointOfLeastRelativeError(long bucketIndex, int scale) For a bucket with the given index, computes the pointxin the bucket such that(x - l) / lequals(u - x) / u, wherelis the lower bucket boundary anduis the upper bucket boundary.static doublegetUpperBucketBoundary(long index, int scale) Returns the upper boundary of the bucket with the given index and scale.
-
Constructor Details
-
ExponentialScaleUtils
public ExponentialScaleUtils()
-
-
Method Details
-
compareExponentiallyScaledValues
public static int compareExponentiallyScaledValues(long idxA, int scaleA, long idxB, int scaleB) Compares the lower boundaries of two buckets, which may have different scales. This is equivalent to a mathematically correct comparison of the lower bucket boundaries. Note that this method allows for scales and indices of the full numeric range of the types.- Parameters:
idxA- the index of the first bucketscaleA- the scale of the first bucketidxB- the index of the second bucketscaleB- the scale of the second bucket- Returns:
- a negative integer, zero, or a positive integer as the first bucket's lower boundary is less than, equal to, or greater than the second bucket's lower boundary
-
getUpperBucketBoundary
public static double getUpperBucketBoundary(long index, int scale) Returns the upper boundary of the bucket with the given index and scale.- Parameters:
index- the index of the bucketscale- the scale of the bucket- Returns:
- the upper boundary of the bucket
-
getLowerBucketBoundary
public static double getLowerBucketBoundary(long index, int scale) Returns the lower boundary of the bucket with the given index and scale.- Parameters:
index- the index of the bucket in the [ExponentialHistogram.MIN_INDEX,ExponentialHistogram.MAX_INDEX] range.scale- the scale of the bucket- Returns:
- the lower boundary of the bucket
-
getPointOfLeastRelativeError
public static double getPointOfLeastRelativeError(long bucketIndex, int scale) For a bucket with the given index, computes the pointxin the bucket such that(x - l) / lequals(u - x) / u, wherelis the lower bucket boundary anduis the upper bucket boundary.
In other words, we select the point in the bucket that has the least relative error with respect to any other point in the bucket.- Parameters:
bucketIndex- the index of the bucketscale- the scale of the bucket- Returns:
- the point of least relative error
-
computeIndex
public static long computeIndex(double value, int scale) Provides the index of the bucket of the exponential histogram with the given scale that contains the provided value.- Parameters:
value- the value to find the bucket forscale- the scale of the histogram- Returns:
- the index of the bucket
-