lint fixes
- Id
- a09a005c93b2751839016418159d7f54c12a7a27
- Author
- Caio
- Commit time
- 2024-04-29T07:55:57+02:00
Modified serialization.go
}
if encoding != smallEncoding {
- return nil, fmt.Errorf("Unsupported encoding version: %d", encoding)
+ return nil, fmt.Errorf("unsupported encoding version: %d", encoding)
}
t, err := newWithoutSummary(options...)
Modified summary.go
func (s *summary) Add(key float64, value uint64) error {
if math.IsNaN(key) {
- return fmt.Errorf("Key must not be NaN")
+ return fmt.Errorf("key must not be NaN")
}
if value == 0 {
return fmt.Errorf("Count must be >0")
Modified tdigest.go
// ElasticSearch), performance metrics for distributed systems, etc.
//
// After you create (and configure, if desired) the digest:
-// digest, err := tdigest.New(tdigest.Compression(100))
+//
+// digest, err := tdigest.New(tdigest.Compression(100))
//
// You can then use it for registering measurements:
-// digest.Add(number)
+//
+// digest.Add(number)
//
// Estimating quantiles:
-// digest.Quantile(0.99)
+//
+// digest.Quantile(0.99)
//
// And merging with another digest:
-// digest.Merge(otherDigest)
+//
+// digest.Merge(otherDigest)
package tdigest
import (
// This will emit an error if `value` is NaN or if `count` is zero.
func (t *TDigest) AddWeighted(value float64, count uint64) (err error) {
if count == 0 {
- return fmt.Errorf("Illegal datapoint <value: %.4f, count: %d>", value, count)
+ return fmt.Errorf("illegal datapoint <value: %.4f, count: %d>", value, count)
}
if t.summary.Len() == 0 {
begin, end := t.findNeighbors(begin, value)
- closest := t.chooseMergeCandidate(begin, end, value, count)
+ closest := t.chooseMergeCandidate(begin, end, count)
if closest == t.summary.Len() {
err = t.summary.Add(value, count)
return start, lastNeighbor
}
-func (t TDigest) chooseMergeCandidate(begin, end int, value float64, count uint64) int {
+func (t TDigest) chooseMergeCandidate(begin, end int, count uint64) int {
closest := t.summary.Len()
sum := t.summary.HeadSum(begin)
var n float32
Modified tdigest_test.go
"sort"
"testing"
- "github.com/leesper/go_rng"
+ rng "github.com/leesper/go_rng"
"gonum.org/v1/gonum/stat"
)
-
-func init() {
- rand.Seed(0xDEADBEE)
-}
func uncheckedNew(options ...tdigestOption) *TDigest {
t, _ := New(options...)
}
}
return t
-}
-
-var sumSizes = []int{10, 100, 1000, 10000}
-
-func BenchmarkSumLoopSimple(b *testing.B) {
- for _, size := range sumSizes {
- size := size
- b.Run(fmt.Sprint(size), func(b *testing.B) {
- benchmarkSumLoopSimple(b, size)
- })
- }
-}
-
-func benchmarkSumLoopSimple(b *testing.B, size int) {
- counts := generateCounts(size)
- indexes := generateIndexes(size)
-
- b.ReportAllocs()
- b.ResetTimer()
- for n := 0; n < b.N; n++ {
- for _, idx := range indexes {
- _ = sumUntilIndexSimple(counts, idx)
- }
- }
-}
-
-func BenchmarkSumLoopUnrolled(b *testing.B) {
- for _, size := range sumSizes {
- size := size
- b.Run(fmt.Sprint(size), func(b *testing.B) {
- benchmarkSumLoopUnrolled(b, size)
- })
- }
-}
-
-func benchmarkSumLoopUnrolled(b *testing.B, size int) {
- counts := generateCounts(size)
- indexes := generateIndexes(size)
-
- b.ReportAllocs()
- b.ResetTimer()
- for n := 0; n < b.N; n++ {
- for _, idx := range indexes {
- _ = sumUntilIndex(counts, idx)
- }
- }
-}
-
-func generateCounts(size int) []uint64 {
- counts := make([]uint64, size)
- for i := 0; i < size; i++ {
- counts[i] = rand.Uint64()
- }
- return counts
-}
-
-func generateIndexes(size int) []int {
- const num = 100
-
- indexes := make([]int, num)
- for i := 0; i < num; i++ {
- indexes[i] = rand.Intn(size)
- }
- return indexes
-}
-
-func sumUntilIndexSimple(counts []uint64, idx int) uint64 {
- var sum uint64
- for _, c := range counts {
- sum += uint64(c)
- }
- return sum
}
// Pathological ordered-input case.