mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-22 18:50:46 -06:00
Histogram: allow for samples > 1 << 63 (#3650)
This commit is contained in:
@@ -38,7 +38,7 @@ func identToString(v uint64) string {
|
||||
return fmt.Sprintf("%d", v)
|
||||
}
|
||||
|
||||
const bucketCount = 63
|
||||
const bucketCount = 64
|
||||
|
||||
// Sample adds a uint64 data point to the histogram
|
||||
func (h *Histogram) Sample(v uint64) {
|
||||
@@ -76,8 +76,8 @@ func (h Histogram) bucketVal(bucket int) uint64 {
|
||||
return 1 << (uint64(bucket))
|
||||
}
|
||||
|
||||
// Sum return the sum of sampled values, given that each sample is clamped to
|
||||
// the mid-point value of the bucket in which it is recorded.
|
||||
// Sum return the sum of sampled values, note that Sum can be overflowed without
|
||||
// overflowing the histogram buckets.
|
||||
func (h Histogram) Sum() uint64 {
|
||||
return h.sum
|
||||
}
|
||||
|
||||
@@ -49,6 +49,14 @@ func TestHistogramBasic(t *testing.T) {
|
||||
assert.Equal(uint64(144), h.Mean())
|
||||
}
|
||||
|
||||
func TestHistogramLarge(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
h := Histogram{}
|
||||
h.Sample(0xfffffffffffffe30)
|
||||
assert.Equal(uint64(1), h.Samples())
|
||||
assert.Equal(uint64(0xfffffffffffffe30), h.Sum())
|
||||
}
|
||||
|
||||
func TestHistogramAdd(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user