added multi

This commit is contained in:
Stephen McQuay 2016-09-22 23:03:32 -07:00
parent c6935de403
commit 323daff95b
No known key found for this signature in database
GPG Key ID: 1ABF428F71BAFC3D

39
multi.go Normal file
View 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
}