added multi
This commit is contained in:
parent
c6935de403
commit
323daff95b
39
multi.go
Normal file
39
multi.go
Normal file
@ -0,0 +1,39 @@
|
||||
package bps
|
||||
|
||||
import "time"
|
||||
|
||||
// Multi wraps multiple BPS
|
||||
type Multi struct {
|
||||
bs []*BPS
|
||||
}
|
||||
|
||||
// NewMulti returns a populated Multi that has a BPS for each provided
|
||||
// duration.
|
||||
func NewMulti(durs ...time.Duration) (*Multi, error) {
|
||||
bs := []*BPS{}
|
||||
for _, d := range durs {
|
||||
b, err := New(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bs = append(bs, b)
|
||||
}
|
||||
r := &Multi{bs}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// Add adds i to each internal BPS.
|
||||
func (mw *Multi) Add(i int64) {
|
||||
for _, b := range mw.bs {
|
||||
b.Add(i)
|
||||
}
|
||||
}
|
||||
|
||||
// Rate returns a slice of rates, one for each BPS.
|
||||
func (mw *Multi) Rate() []float64 {
|
||||
r := []float64{}
|
||||
for _, b := range mw.bs {
|
||||
r = append(r, b.Rate())
|
||||
}
|
||||
return r
|
||||
}
|
Loading…
Reference in New Issue
Block a user