java.lang.Object
org.elasticsearch.exponentialhistogram.ExponentialScaleUtils

public class ExponentialScaleUtils extends Object
A collection of utility methods for working with indices and scales of exponential bucket histograms.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    compareExponentiallyScaledValues(long idxA, int scaleA, long idxB, int scaleB)
    Compares the lower boundaries of two buckets, which may have different scales.
    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.
    static double
    getLowerBucketBoundary(long index, int scale)
    Returns the lower boundary of the bucket with the given index and scale.
    static double
    getPointOfLeastRelativeError(long bucketIndex, int scale)
    For a bucket with the given index, computes the point x in the bucket such that (x - l) / l equals (u - x) / u, where l is the lower bucket boundary and u is the upper bucket boundary.
    static double
    getUpperBucketBoundary(long index, int scale)
    Returns the upper boundary of the bucket with the given index and scale.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 bucket
      scaleA - the scale of the first bucket
      idxB - the index of the second bucket
      scaleB - 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 bucket
      scale - 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 point x in the bucket such that (x - l) / l equals (u - x) / u, where l is the lower bucket boundary and u is 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 bucket
      scale - 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 for
      scale - the scale of the histogram
      Returns:
      the index of the bucket