caio.co/de/go-tdigest

Rename `Update()` to `Add()`

Trying to keep the interface closer to the reference implementation.
Arguably it's a better name anyway since we're adding a new datapoint to
the summary.
Id
eb88f1091716fb94486aef60bcba003d7697095a
Author
Caio
Commit time
2015-08-26T16:53:56-03:00

Modified README.md

@@ -28,7 +28,7
var t = tdigest.New(100)

for i := 0; i < 10000; i++ {
- t.Update(rand.Float64(), 1)
+ t.Add(rand.Float64(), 1)
}

fmt.Printf("p(.5) = %.6f\n", t.Percentile(0.5))

Modified serialization.go

@@ -106,7 +106,7
return nil, err
}

- t.Update(float64(means[i])+x, decUint)
+ t.Add(float64(means[i])+x, decUint)
x = float64(means[i])
}

Modified tdigest.go

@@ -109,12 +109,12
return t.summary.Max().mean
}

-// Update registers a new sample in the digest.
+// Add registers a new sample in the digest.
// It's the main entry point for the digest and very likely the only
// method to be used for collecting samples. The count parameter is for
// when you are registering a sample that occurred multiple times - the
// most common value for this is 1.
-func (t *TDigest) Update(value float64, count uint32) error {
+func (t *TDigest) Add(value float64, count uint32) error {

if count == 0 {
return fmt.Errorf("Illegal datapoint <value: %.4f, count: %d>", value, count)
@@ -177,7 +177,7
shuffle(nodes)

for _, item := range nodes {
- t.Update(item.mean, item.count)
+ t.Add(item.mean, item.count)
}
}

@@ -195,7 +195,7
shuffle(nodes)

for _, item := range nodes {
- t.Update(item.mean, item.count)
+ t.Add(item.mean, item.count)
}
}

Modified tdigest_test.go

@@ -155,7 +155,7
t.Errorf("Adding centroids with same mean should increment the count only. Got %s", y)
}

- err := tdigest.Update(0, 0)
+ err := tdigest.Add(0, 0)

if err == nil {
t.Errorf("Expected Update() to error out with input (0,0)")
@@ -175,7 +175,7
tdigest := New(100)

for i := 0; i < 10000; i++ {
- tdigest.Update(rand.Float64(), 1)
+ tdigest.Add(rand.Float64(), 1)
}

assertDifferenceSmallerThan(tdigest, 0.5, 0.02, t)
@@ -193,7 +193,7

// FIXME Timeout after X seconds of something?
for i := 0; i < 10000; i++ {
- tdigest.Update(float64(i), 1)
+ tdigest.Add(float64(i), 1)
}
}

@@ -201,9 +201,9
t.Parallel()
tdigest := New(100)

- tdigest.Update(1, 1)
- tdigest.Update(2, 1)
- tdigest.Update(3, 1)
+ tdigest.Add(1, 1)
+ tdigest.Add(2, 1)
+ tdigest.Add(3, 1)

if tdigest.Percentile(0.5) != 2 {
t.Errorf("Expected p(0.5) = 2, Got %.2f instead", tdigest.Percentile(0.5))
@@ -212,7 +212,7
tdigest = New(100)

for _, i := range []float64{1, 2, 2, 2, 2, 2, 2, 2, 3} {
- tdigest.Update(i, 1)
+ tdigest.Add(i, 1)
}

if tdigest.Percentile(0.5) != 2 {
@@ -267,9 +267,9
num := rand.Float64()

data[i] = num
- dist1.Update(num, 1)
+ dist1.Add(num, 1)
for j := 0; j < numSubs; j++ {
- subs[j].Update(num, 1)
+ subs[j].Add(num, 1)
}
}

@@ -323,7 +323,7
// so we don't end up compressing automatically
t1 := New(100)
for i := 0; i < 100; i++ {
- t1.Update(rand.Float64(), 1)
+ t1.Add(rand.Float64(), 1)
}

serialized, _ := t1.AsBytes()
@@ -338,7 +338,7
func benchmarkUpdate(compression float64, b *testing.B) {
t := New(compression)
for n := 0; n < b.N; n++ {
- t.Update(rand.Float64(), 1)
+ t.Add(rand.Float64(), 1)
}
}