- When bucketForPercentile was re-written and replaced with bucketForPercentile2,

the original and deprecated function was never deleted and migrated.  This has
  been done.
- Update associated tests, which were originally inaccurate, to correct expectations!
This commit is contained in:
Matt T. Proud 2012-05-20 00:10:52 +02:00
parent 5a56c47909
commit 4d91ee5f5c
2 changed files with 89 additions and 134 deletions

View File

@ -110,56 +110,6 @@ func (h *Histogram) Humanize() string {
return string(stringBuffer.Bytes()) return string(stringBuffer.Bytes())
} }
// Find what bucket and element index contains a given percentile value.
// If a percentile is requested that results in a corresponding index that is no
// longer contained by the bucket, the index of the last item is returned. This
// may occur if the underlying bucket catalogs values and employs an eviction
// strategy.
func (h *Histogram) bucketForPercentile(percentile float64) (bucket *Bucket, index int) {
var totalObservations int = 0
for _, bucket := range h.buckets {
totalObservations += bucket.Observations()
}
expectedIndex := int(math.Floor(percentile * float64(totalObservations)))
var accumulatedObservations int = 0
var lastBucket Bucket = nil
var lastAccumulatedObservations int = 0
for _, bucket := range h.buckets {
if lastBucket == nil {
lastBucket = bucket
}
observations := bucket.Observations()
accumulatedObservations += observations
if observations == 0 {
continue
}
if accumulatedObservations > expectedIndex {
break
} else if accumulatedObservations == expectedIndex {
lastBucket = bucket
break
}
lastAccumulatedObservations = accumulatedObservations
lastBucket = bucket
}
var offset int
offset = int(expectedIndex - lastAccumulatedObservations)
if offset > 0 {
offset--
}
return &lastBucket, offset
}
func previousCumulativeObservations(cumulativeObservations []int, bucketIndex int) int { func previousCumulativeObservations(cumulativeObservations []int, bucketIndex int) int {
if bucketIndex == 0 { if bucketIndex == 0 {
return 0 return 0
@ -172,7 +122,12 @@ func prospectiveIndexForPercentile(percentile float64, totalObservations int) in
return int(math.Floor(percentile * float64(totalObservations))) return int(math.Floor(percentile * float64(totalObservations)))
} }
func (h *Histogram) bucketForPercentile2(percentile float64) (bucket *Bucket, index int) { // Find what bucket and element index contains a given percentile value.
// If a percentile is requested that results in a corresponding index that is no
// longer contained by the bucket, the index of the last item is returned. This
// may occur if the underlying bucket catalogs values and employs an eviction
// strategy.
func (h *Histogram) bucketForPercentile(percentile float64) (bucket *Bucket, index int) {
bucketCount := len(h.buckets) bucketCount := len(h.buckets)
observationsByBucket := make([]int, bucketCount) observationsByBucket := make([]int, bucketCount)
@ -217,7 +172,7 @@ func (h *Histogram) bucketForPercentile2(percentile float64) (bucket *Bucket, in
// collected samples. The requested percentile is expected to be a real // collected samples. The requested percentile is expected to be a real
// value within (0, 1.0]. // value within (0, 1.0].
func (h *Histogram) Percentile(percentile float64) float64 { func (h *Histogram) Percentile(percentile float64) float64 {
bucket, index := h.bucketForPercentile2(percentile) bucket, index := h.bucketForPercentile(percentile)
return (*bucket).ValueForIndex(index) return (*bucket).ValueForIndex(index)
} }

View File

@ -86,13 +86,13 @@ func (s *S) TestBucketForPercentile(c *C) {
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 0) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 0) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile(1.0) bucket, subindex = h.bucketForPercentile(1.0)
@ -124,7 +124,7 @@ func (s *S) TestBucketForPercentile(c *C) {
bucket, subindex = h.bucketForPercentile(0.51) bucket, subindex = h.bucketForPercentile(0.51)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 51) c.Check((*bucket).Observations(), Equals, 51)
} }
@ -142,7 +142,7 @@ func (s *S) TestBucketForPercentileSingleton(c *C) {
var subindex int = 0 var subindex int = 0
for i := 0.0; i < 1.0; i += 0.01 { for i := 0.0; i < 1.0; i += 0.01 {
bucket, subindex := h.bucketForPercentile2(i) bucket, subindex := h.bucketForPercentile(i)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -150,19 +150,19 @@ func (s *S) TestBucketForPercentileSingleton(c *C) {
h.Add(0.0) h.Add(0.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -173,7 +173,7 @@ func (s *S) TestBucketForPercentileSingleton(c *C) {
c.Assert(h, Not(IsNil)) c.Assert(h, Not(IsNil))
for i := 0.0; i < 1.0; i += 0.01 { for i := 0.0; i < 1.0; i += 0.01 {
bucket, subindex := h.bucketForPercentile2(i) bucket, subindex := h.bucketForPercentile(i)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -181,19 +181,19 @@ func (s *S) TestBucketForPercentileSingleton(c *C) {
h.Add(1.0) h.Add(1.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -212,19 +212,19 @@ func (s *S) TestBucketForPercentileSingleton(c *C) {
h.Add(2.0) h.Add(2.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -245,7 +245,7 @@ func (s *S) TestBucketForPercentileDoubleInSingleBucket(c *C) {
var subindex int = 0 var subindex int = 0
for i := 0.0; i < 1.0; i += 0.01 { for i := 0.0; i < 1.0; i += 0.01 {
bucket, subindex := h.bucketForPercentile2(i) bucket, subindex := h.bucketForPercentile(i)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -254,19 +254,19 @@ func (s *S) TestBucketForPercentileDoubleInSingleBucket(c *C) {
h.Add(0.0) h.Add(0.0)
h.Add(0.0) h.Add(0.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -277,7 +277,7 @@ func (s *S) TestBucketForPercentileDoubleInSingleBucket(c *C) {
c.Assert(h, Not(IsNil)) c.Assert(h, Not(IsNil))
for i := 0.0; i < 1.0; i += 0.01 { for i := 0.0; i < 1.0; i += 0.01 {
bucket, subindex := h.bucketForPercentile2(i) bucket, subindex := h.bucketForPercentile(i)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -286,19 +286,19 @@ func (s *S) TestBucketForPercentileDoubleInSingleBucket(c *C) {
h.Add(1.0) h.Add(1.0)
h.Add(1.0) h.Add(1.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -318,19 +318,19 @@ func (s *S) TestBucketForPercentileDoubleInSingleBucket(c *C) {
h.Add(2.0) h.Add(2.0)
h.Add(2.0) h.Add(2.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -351,7 +351,7 @@ func (s *S) TestBucketForPercentileTripleInSingleBucket(c *C) {
var subindex int = 0 var subindex int = 0
for i := 0.0; i < 1.0; i += 0.01 { for i := 0.0; i < 1.0; i += 0.01 {
bucket, subindex := h.bucketForPercentile2(i) bucket, subindex := h.bucketForPercentile(i)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -361,37 +361,37 @@ func (s *S) TestBucketForPercentileTripleInSingleBucket(c *C) {
h.Add(0.0) h.Add(0.0)
h.Add(0.0) h.Add(0.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -403,37 +403,37 @@ func (s *S) TestBucketForPercentileTripleInSingleBucket(c *C) {
h.Add(1.0) h.Add(1.0)
h.Add(1.0) h.Add(1.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -445,37 +445,37 @@ func (s *S) TestBucketForPercentileTripleInSingleBucket(c *C) {
h.Add(2.0) h.Add(2.0)
h.Add(2.0) h.Add(2.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 2) c.Check(subindex, Equals, 2)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 3) c.Check((*bucket).Observations(), Equals, 3)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -496,7 +496,7 @@ func (s *S) TestBucketForPercentileTwoEqualAdjacencies(c *C) {
var subindex int = 0 var subindex int = 0
for i := 0.0; i < 1.0; i += 0.01 { for i := 0.0; i < 1.0; i += 0.01 {
bucket, subindex := h.bucketForPercentile2(i) bucket, subindex := h.bucketForPercentile(i)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -505,37 +505,37 @@ func (s *S) TestBucketForPercentileTwoEqualAdjacencies(c *C) {
h.Add(0.0) h.Add(0.0)
h.Add(1.0) h.Add(1.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -546,37 +546,37 @@ func (s *S) TestBucketForPercentileTwoEqualAdjacencies(c *C) {
h.Add(1.0) h.Add(1.0)
h.Add(2.0) h.Add(2.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -597,7 +597,7 @@ func (s *S) TestBucketForPercentileTwoAdjacenciesUnequal(c *C) {
var subindex int = 0 var subindex int = 0
for i := 0.0; i < 1.0; i += 0.01 { for i := 0.0; i < 1.0; i += 0.01 {
bucket, subindex := h.bucketForPercentile2(i) bucket, subindex := h.bucketForPercentile(i)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -607,37 +607,37 @@ func (s *S) TestBucketForPercentileTwoAdjacenciesUnequal(c *C) {
h.Add(0.0) h.Add(0.0)
h.Add(1.0) h.Add(1.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -649,37 +649,37 @@ func (s *S) TestBucketForPercentileTwoAdjacenciesUnequal(c *C) {
h.Add(1.0) h.Add(1.0)
h.Add(1.0) h.Add(1.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -691,37 +691,37 @@ func (s *S) TestBucketForPercentileTwoAdjacenciesUnequal(c *C) {
h.Add(1.0) h.Add(1.0)
h.Add(2.0) h.Add(2.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
@ -733,37 +733,37 @@ func (s *S) TestBucketForPercentileTwoAdjacenciesUnequal(c *C) {
h.Add(2.0) h.Add(2.0)
h.Add(2.0) h.Add(2.0)
bucket, subindex = h.bucketForPercentile2(1.0) bucket, subindex = h.bucketForPercentile(1.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.67) bucket, subindex = h.bucketForPercentile(0.67)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(2.0 / 3.0) bucket, subindex = h.bucketForPercentile(2.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 1) c.Check(subindex, Equals, 1)
c.Check((*bucket).Observations(), Equals, 2) c.Check((*bucket).Observations(), Equals, 2)
bucket, subindex = h.bucketForPercentile2(0.5) bucket, subindex = h.bucketForPercentile(0.5)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(1.0 / 3.0) bucket, subindex = h.bucketForPercentile(1.0 / 3.0)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)
c.Check((*bucket).Observations(), Equals, 1) c.Check((*bucket).Observations(), Equals, 1)
bucket, subindex = h.bucketForPercentile2(0.01) bucket, subindex = h.bucketForPercentile(0.01)
c.Assert(*bucket, Not(IsNil)) c.Assert(*bucket, Not(IsNil))
c.Check(subindex, Equals, 0) c.Check(subindex, Equals, 0)