|
@@ -28,6 +28,7 @@ type Sample interface {
|
|
|
Percentiles([]float64) []float64
|
|
Percentiles([]float64) []float64
|
|
|
Size() int
|
|
Size() int
|
|
|
StdDev() float64
|
|
StdDev() float64
|
|
|
|
|
+ Sum() int64
|
|
|
Update(int64)
|
|
Update(int64)
|
|
|
Values() []int64
|
|
Values() []int64
|
|
|
Variance() float64
|
|
Variance() float64
|
|
@@ -134,6 +135,11 @@ func (s *ExpDecaySample) StdDev() float64 {
|
|
|
return SampleStdDev(s.Values())
|
|
return SampleStdDev(s.Values())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Sum returns the sum of the sample.
|
|
|
|
|
+func (s *ExpDecaySample) Sum() int64 {
|
|
|
|
|
+ return SampleSum(s.Values())
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// Update samples a new value.
|
|
// Update samples a new value.
|
|
|
func (s *ExpDecaySample) Update(v int64) {
|
|
func (s *ExpDecaySample) Update(v int64) {
|
|
|
s.update(time.Now(), v)
|
|
s.update(time.Now(), v)
|
|
@@ -216,6 +222,9 @@ func (NilSample) Size() int { return 0 }
|
|
|
// No-op.
|
|
// No-op.
|
|
|
func (NilSample) StdDev() float64 { return 0.0 }
|
|
func (NilSample) StdDev() float64 { return 0.0 }
|
|
|
|
|
|
|
|
|
|
+// No-op.
|
|
|
|
|
+func (NilSample) Sum() int64 { return 0 }
|
|
|
|
|
+
|
|
|
// No-op.
|
|
// No-op.
|
|
|
func (NilSample) Update(v int64) {}
|
|
func (NilSample) Update(v int64) {}
|
|
|
|
|
|
|
@@ -244,11 +253,7 @@ func SampleMean(values []int64) float64 {
|
|
|
if 0 == len(values) {
|
|
if 0 == len(values) {
|
|
|
return 0.0
|
|
return 0.0
|
|
|
}
|
|
}
|
|
|
- var sum int64
|
|
|
|
|
- for _, v := range values {
|
|
|
|
|
- sum += v
|
|
|
|
|
- }
|
|
|
|
|
- return float64(sum) / float64(len(values))
|
|
|
|
|
|
|
+ return float64(SampleSum(values)) / float64(len(values))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// SampleMin returns the minimum value of the slice of int64.
|
|
// SampleMin returns the minimum value of the slice of int64.
|
|
@@ -298,6 +303,15 @@ func SampleStdDev(values []int64) float64 {
|
|
|
return math.Sqrt(SampleVariance(values))
|
|
return math.Sqrt(SampleVariance(values))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// SampleSum returns the sum of the slice of int64.
|
|
|
|
|
+func SampleSum(values []int64) int64 {
|
|
|
|
|
+ var sum int64
|
|
|
|
|
+ for _, v := range values {
|
|
|
|
|
+ sum += v
|
|
|
|
|
+ }
|
|
|
|
|
+ return sum
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// SampleVariance returns the variance of the slice of int64.
|
|
// SampleVariance returns the variance of the slice of int64.
|
|
|
func SampleVariance(values []int64) float64 {
|
|
func SampleVariance(values []int64) float64 {
|
|
|
m := SampleMean(values)
|
|
m := SampleMean(values)
|
|
@@ -405,6 +419,11 @@ func (s *UniformSample) StdDev() float64 {
|
|
|
return SampleStdDev(s.values)
|
|
return SampleStdDev(s.values)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Sum returns the sum of the sample.
|
|
|
|
|
+func (s *UniformSample) Sum() int64 {
|
|
|
|
|
+ return SampleSum(s.values)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// Update the sample with a new value.
|
|
// Update the sample with a new value.
|
|
|
func (s *UniformSample) Update(v int64) {
|
|
func (s *UniformSample) Update(v int64) {
|
|
|
s.mutex.Lock()
|
|
s.mutex.Lock()
|