|
|
@ -120,9 +120,9 @@ type window struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newWindow(size int) *window {
|
|
|
|
func newWindow(size int) *window {
|
|
|
|
var buckets []*Bucket
|
|
|
|
buckets := make([]*Bucket, size)
|
|
|
|
for i := 0; i < size; i++ {
|
|
|
|
for i := 0; i < size; i++ {
|
|
|
|
buckets = append(buckets, new(Bucket))
|
|
|
|
buckets[i] = new(Bucket)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &window{
|
|
|
|
return &window{
|
|
|
|
buckets: buckets,
|
|
|
|
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)) {
|
|
|
|
func (w *window) reduce(start, count int, fn func(b *Bucket)) {
|
|
|
|
for i := 0; i < count; i++ {
|
|
|
|
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) {
|
|
|
|
func (w *window) resetBucket(offset int) {
|
|
|
|
w.buckets[offset].reset()
|
|
|
|
w.buckets[offset%w.size].reset()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func IgnoreCurrentBucket() RollingWindowOption {
|
|
|
|
func IgnoreCurrentBucket() RollingWindowOption {
|
|
|
|