caio.co/de/go-tdigest

Add TDigest.Reset

Id
a45b433de67585f248c177c5cc4ea3268aa02cce
Author
Nova
Commit time
2025-08-14T17:33:08+07:00

Modified summary.go

@@ -161,6 +161,11
}
}

+func (s *summary) Reset() {
+ s.means = s.means[:0]
+ s.counts = s.counts[:0]
+}
+
// Randomly shuffles summary contents, so they can be added to another summary
// with being pathological. Renders summary invalid.
func (s *summary) shuffle(rng RNG) {

Modified tdigest.go

@@ -342,6 +342,13
}
}

+// Reset resets a TDigest to its initial state, keeping its capacity.
+func (t *TDigest) Reset() {
+ t.summary.Reset()
+ t.count = 0
+}
+
+
func interpolate(x, x0, x1 float64) float64 {
return (x - x0) / (x1 - x0)
}