some optimize by kevwan and benying (#240)

Co-authored-by: 杨志泉 <zhiquan.yang@yiducloud.cn>
master
benying 4 years ago committed by GitHub
parent 4b5c2de376
commit 7d1b43780a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 {

Loading…
Cancel
Save