java.lang.Object
org.elasticsearch.exponentialhistogram.ZeroBucket

public final class ZeroBucket extends Object
Represents the bucket for values around zero in an exponential histogram. The range of this bucket is [-zeroThreshold, +zeroThreshold]. To allow efficient comparison with bucket boundaries, this class internally represents the zero threshold as a exponential histogram bucket index with a scale, computed via ExponentialScaleUtils.computeIndex(double, int).
  • Field Details

    • SHALLOW_SIZE

      public static final long SHALLOW_SIZE
  • Method Details

    • minimalEmpty

      public static ZeroBucket minimalEmpty()
      Returns:
      A singleton instance of an empty zero bucket with the smallest possible threshold.
    • minimalWithCount

      public static ZeroBucket minimalWithCount(long count)
      Creates a zero bucket with the smallest possible threshold and a given count.
      Parameters:
      count - The number of values in the bucket.
      Returns:
      A new ZeroBucket.
    • create

      public static ZeroBucket create(double zeroThreshold, long count)
      Creates a zero bucket from the given threshold represented as double.
      Parameters:
      zeroThreshold - the zero threshold defining the bucket range [-zeroThreshold, +zeroThreshold], must be non-negative
      count - the number of values in the bucket
      Returns:
      the new ZeroBucket
    • create

      public static ZeroBucket create(long index, int scale, long count)
      Creates a zero bucket from the given threshold represented as exponentially scaled number.
      Parameters:
      index - the index of the exponentially scaled number defining the zero threshold
      scale - the corresponding scale for the index
      count - the number of values in the bucket
      Returns:
      the new ZeroBucket
    • zeroThreshold

      public double zeroThreshold()
      Returns:
      The value of the zero threshold.
    • index

      public long index()
    • scale

      public int scale()
    • count

      public long count()
    • isIndexBased

      public boolean isIndexBased()
      Returns:
      True if the zero threshold was created from an index/scale pair, false if it was created from a real-valued threshold.
    • merge

      public ZeroBucket merge(ZeroBucket other)
      Merges this zero bucket with another one.
      • If the other zero bucket or both are empty, this instance is returned unchanged.
      • If the this zero bucket is empty and the other one is populated, the other instance is returned unchanged.
      • Otherwise, the zero threshold is increased if necessary (by taking the maximum of the two), and the counts are summed.
      Parameters:
      other - The other zero bucket to merge with.
      Returns:
      A new ZeroBucket representing the merged result.
    • collapseOverlappingBucketsForAll

      public ZeroBucket collapseOverlappingBucketsForAll(BucketIterator... bucketIterators)
      Collapses all buckets from the given iterators whose lower boundaries are smaller than the zero threshold. The iterators are advanced to point at the first, non-collapsed bucket.
      Parameters:
      bucketIterators - The iterators whose buckets may be collapsed.
      Returns:
      A potentially updated ZeroBucket with the collapsed buckets' counts and an adjusted threshold.
    • compareZeroThreshold

      public int compareZeroThreshold(ZeroBucket other)
      Compares the zero threshold of this bucket with another one.
      Parameters:
      other - The other zero bucket to compare against.
      Returns:
      A negative integer, zero, or a positive integer if this bucket's threshold is less than, equal to, or greater than the other's.
    • collapseOverlappingBuckets

      public ZeroBucket collapseOverlappingBuckets(BucketIterator buckets)
      Collapses all buckets from the given iterator whose lower boundaries are smaller than the zero threshold. The iterator is advanced to point at the first, non-collapsed bucket.
      Parameters:
      buckets - The iterator whose buckets may be collapsed.
      Returns:
      A potentially updated ZeroBucket with the collapsed buckets' counts and an adjusted threshold.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object