diff --git a/core/collection/rollingwindow.go b/core/collection/rollingwindow.go index c9f45aaf..b6fbe408 100644 --- a/core/collection/rollingwindow.go +++ b/core/collection/rollingwindow.go @@ -120,9 +120,9 @@ type window struct { } func newWindow(size int) *window { - var buckets []*Bucket + buckets := make([]*Bucket, size) for i := 0; i < size; i++ { - buckets = append(buckets, new(Bucket)) + buckets[i] = new(Bucket) } return &window{ buckets: buckets, @@ -136,12 +136,12 @@ func (w *window) add(offset int, v float64) { func (w *window) reduce(start, count int, fn func(b *Bucket)) { for i := 0; i < count; i++ { - fn(w.buckets[(start+i)%len(w.buckets)]) + fn(w.buckets[(start+i)%w.size]) } } func (w *window) resetBucket(offset int) { - w.buckets[offset].reset() + w.buckets[offset%w.size].reset() } func IgnoreCurrentBucket() RollingWindowOption {