caio.co/de/go-tdigest

Tidy things up [gometalinter]

Id
b33cc5b128687edc039f39f2e2dac2502431d159
Author
Caio
Commit time
2017-10-29T10:27:47+01:00

Modified options.go

@@ -17,7 +17,7
//
// Compression must be a value greater of equal to 1, will yield an
// error otherwise.
-func Compression(compression uint32) tdigestOption {
+func Compression(compression uint32) tdigestOption { // nolint
return func(t *TDigest) error {
if compression < 1 {
return errors.New("Compression should be >= 1")
@@ -36,7 +36,7
// particularly useful for testing or when you want to disconnect
// your sample collection from the (default) shared random source
// to minimize lock contention.
-func RandomNumberGenerator(rng TDigestRNG) tdigestOption {
+func RandomNumberGenerator(rng RNG) tdigestOption { // nolint
return func(t *TDigest) error {
t.rng = rng
return nil
@@ -46,6 +46,6
// LocalRandomNumberGenerator makes the TDigest use the default
// `math/random` functions but with an unshared source that is
// seeded with the given `seed` parameter.
-func LocalRandomNumberGenerator(seed int64) tdigestOption {
+func LocalRandomNumberGenerator(seed int64) tdigestOption { // nolint
return RandomNumberGenerator(newLocalRNG(seed))
}

Modified rng.go

@@ -1,10 +1,12
package tdigest

import (
"math/rand"
)

-type TDigestRNG interface {
+// RNG is an interface that wraps the needed random number
+// generator calls that tdigest uses during its runtime
+type RNG interface {
Float32() float32
Intn(int) int
}

Modified summary_test.go

@@ -79,7 +79,7
s := newSummary(10)

for _, i := range []float64{10, 10, 10, 10, 10} {
- s.Add(i, 1)
+ _ = s.Add(i, 1)
}

s.setAt(0, 30, 1)
@@ -129,7 +129,7
var total uint32
for i := 0; i < 100; i++ {
count := uint32(rand.Intn(10) + 1)
- s.Add(rand.Float64(), count)
+ _ = s.Add(rand.Float64(), count)
total += count
}

@@ -152,7 +152,7
func TestFloor(t *testing.T) {
s := newSummary(200)
for i := float64(0); i < 101; i++ {
- s.Add(i/2.0, 1)
+ _ = s.Add(i/2.0, 1)
}

if s.Floor(-30) != -1 {

Modified tdigest.go

@@ -30,7 +30,7
summary *summary
compression float64
count uint64
- rng TDigestRNG
+ rng RNG
}

// New creates a new digest.
@@ -185,7 +185,10
}

if closest == t.summary.Len() {
- t.summary.Add(value, count)
+ err = t.summary.Add(value, count)
+ if err != nil {
+ return err
+ }
} else {
c := float64(t.summary.Count(closest))
newMean := weightedAverage(t.summary.Mean(closest), c, value, float64(count))
@@ -220,7 +223,7
return t.count
}

-// Add(x) is an alias for AddWeighted(x,1)
+// Add is an alias for AddWeighted(x,1)
// Read the documentation for AddWeighted for more details.
func (t *TDigest) Add(value float64) error {
return t.AddWeighted(value, 1)
@@ -285,9 +288,8
} else if t.summary.Len() == 1 {
if value < t.summary.Mean(0) {
return 0
- } else {
- return 1
}
+ return 1
}

// We have at least 2 centroids
@@ -331,7 +333,7
t.summary.ForEach(f)
}

-func shuffle(means []float64, counts []uint32, rng TDigestRNG) {
+func shuffle(means []float64, counts []uint32, rng RNG) {
for i := len(means) - 1; i > 1; i-- {
j := rng.Intn(i + 1)
means[i], means[j], counts[i], counts[j] = means[j], means[i], counts[j], counts[i]

Modified tdigest_test.go

@@ -171,10 +171,10
func TestSingletonInACrowd(t *testing.T) {
tdigest := uncheckedNew()
for i := 0; i < 10000; i++ {
- tdigest.Add(10)
+ _ = tdigest.Add(10)
}
- tdigest.Add(20)
- tdigest.Compress()
+ _ = tdigest.Add(20)
+ _ = tdigest.Compress()

for _, q := range []float64{0, 0.5, 0.8, 0.9, 0.99, 0.999} {
if q == 0.999 {
@@ -199,7 +199,7

data := []float64{0, 279, 2, 281}
for _, f := range data {
- tdigest.Add(f)
+ _ = tdigest.Add(f)
}

quantiles := []float64{0.01, 0.25, 0.5, 0.75, 0.999}
@@ -317,14 +317,14

data[i] = num
_ = dist.Add(num)
- subs[i%numSubs].Add(num)
+ _ = subs[i%numSubs].Add(num)
}

- dist.Compress()
+ _ = dist.Compress()

dist2 := uncheckedNew()
for i := 0; i < numSubs; i++ {
- dist2.Merge(subs[i])
+ _ = dist2.Merge(subs[i])
}

if dist.Count() != dist2.Count() {
@@ -399,7 +399,7
data := make([]float64, numItems)
for i := 0; i < numItems; i++ {
data[i] = gammaRNG.Gamma(0.1, 0.1)
- digest.Add(data[i])
+ _ = digest.Add(data[i])
}

sort.Float64s(data)