Tidy things up [gometalinter]
- Id
- b33cc5b128687edc039f39f2e2dac2502431d159
- Author
- Caio
- Commit time
- 2017-10-29T10:27:47+01:00
Modified options.go
//
// 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")
// 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
// 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
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
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)
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
}
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
summary *summary
compression float64
count uint64
- rng TDigestRNG
+ rng RNG
}
// New creates a new digest.
}
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))
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)
} 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
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
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 {
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}
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() {
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)