Package org.apache.cassandra.utils
Class EstimatedHistogram
- java.lang.Object
-
- org.apache.cassandra.utils.EstimatedHistogram
-
- All Implemented Interfaces:
java.util.function.DoubleToLongFunction
public class EstimatedHistogram extends java.lang.Object implements java.util.function.DoubleToLongFunction
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EstimatedHistogram.EstimatedHistogramSerializer
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BUCKET_COUNT
static EstimatedHistogram.EstimatedHistogramSerializer
serializer
-
Constructor Summary
Constructors Constructor Description EstimatedHistogram()
EstimatedHistogram(int bucketCount)
EstimatedHistogram(int bucketCount, boolean considerZeroes)
EstimatedHistogram(long[] bucketData)
Create EstimatedHistogram from only bucket data.EstimatedHistogram(long[] offsets, long[] bucketData)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(long n)
Increments the count of the bucket closest to n, rounding UP.void
add(long n, long delta)
Increments the count of the bucket closest to n, rounding UP by deltalong
applyAsLong(double value)
void
clearOverflow()
Resets the count in the overflow bucket to zero.long
count()
boolean
equals(java.lang.Object o)
long[]
getBucketOffsets()
long[]
getBuckets(boolean reset)
long
getLargestBucketOffset()
int
hashCode()
boolean
isOverflowed()
void
log(org.slf4j.Logger log)
log.debug() every record in the histogramlong
max()
long
mean()
long
min()
static long[]
newOffsets(int size, boolean considerZeroes)
long
overflowCount()
long
percentile(double percentile)
double
rawMean()
-
-
-
Field Detail
-
serializer
public static final EstimatedHistogram.EstimatedHistogramSerializer serializer
-
DEFAULT_BUCKET_COUNT
public static final int DEFAULT_BUCKET_COUNT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
EstimatedHistogram
public EstimatedHistogram()
-
EstimatedHistogram
public EstimatedHistogram(int bucketCount)
-
EstimatedHistogram
public EstimatedHistogram(int bucketCount, boolean considerZeroes)
-
EstimatedHistogram
public EstimatedHistogram(long[] bucketData)
Create EstimatedHistogram from only bucket data.- Parameters:
bucketData
- bucket data
-
EstimatedHistogram
public EstimatedHistogram(long[] offsets, long[] bucketData)
-
-
Method Detail
-
newOffsets
public static long[] newOffsets(int size, boolean considerZeroes)
-
getBucketOffsets
public long[] getBucketOffsets()
- Returns:
- the histogram values corresponding to each bucket index
-
add
public void add(long n)
Increments the count of the bucket closest to n, rounding UP.- Parameters:
n
-
-
add
public void add(long n, long delta)
Increments the count of the bucket closest to n, rounding UP by delta- Parameters:
n
-
-
getBuckets
public long[] getBuckets(boolean reset)
- Parameters:
reset
- zero out buckets afterwards if true- Returns:
- a long[] containing the current histogram buckets
-
min
public long min()
- Returns:
- the smallest value that could have been added to this histogram
-
max
public long max()
- Returns:
- the largest value that could have been added to this histogram. If the histogram overflowed, returns Long.MAX_VALUE.
-
percentile
public long percentile(double percentile)
- Parameters:
percentile
-- Returns:
- estimated value at given percentile
-
mean
public long mean()
- Returns:
- the ceil of mean histogram value (average of bucket offsets, weighted by count)
- Throws:
java.lang.IllegalStateException
- if any values were greater than the largest bucket threshold
-
rawMean
public double rawMean()
- Returns:
- the mean histogram value (average of bucket offsets, weighted by count)
- Throws:
java.lang.IllegalStateException
- if any values were greater than the largest bucket threshold
-
count
public long count()
- Returns:
- the total number of non-zero values
-
getLargestBucketOffset
public long getLargestBucketOffset()
- Returns:
- the largest bucket offset
-
isOverflowed
public boolean isOverflowed()
- Returns:
- true if a value larger than our largest bucket offset has been recorded, and false otherwise
-
overflowCount
public long overflowCount()
- Returns:
- the number of recorded values larger than the largest bucket offset
-
clearOverflow
public void clearOverflow()
Resets the count in the overflow bucket to zero. Subsequent calls toisOverflowed()
will return false.
-
log
public void log(org.slf4j.Logger log)
log.debug() every record in the histogram- Parameters:
log
-
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
applyAsLong
public long applyAsLong(double value)
- Specified by:
applyAsLong
in interfacejava.util.function.DoubleToLongFunction
-
-