Merge pull request #77510 from wojtek-t/revert_beorn7

Revert "github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973"
This commit is contained in:
Kubernetes Prow Robot
2019-05-06 08:31:42 -07:00
committed by GitHub
18 changed files with 29 additions and 46 deletions

View File

@@ -77,20 +77,15 @@ func NewHighBiased(epsilon float64) *Stream {
// is guaranteed to be within (Quantile±Epsilon).
//
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
func NewTargeted(targetMap map[float64]float64) *Stream {
// Convert map to slice to avoid slow iterations on a map.
// ƒ is called on the hot path, so converting the map to a slice
// beforehand results in significant CPU savings.
targets := targetMapToSlice(targetMap)
func NewTargeted(targets map[float64]float64) *Stream {
ƒ := func(s *stream, r float64) float64 {
var m = math.MaxFloat64
var f float64
for _, t := range targets {
if t.quantile*s.n <= r {
f = (2 * t.epsilon * r) / t.quantile
for quantile, epsilon := range targets {
if quantile*s.n <= r {
f = (2 * epsilon * r) / quantile
} else {
f = (2 * t.epsilon * (s.n - r)) / (1 - t.quantile)
f = (2 * epsilon * (s.n - r)) / (1 - quantile)
}
if f < m {
m = f
@@ -101,25 +96,6 @@ func NewTargeted(targetMap map[float64]float64) *Stream {
return newStream(ƒ)
}
type target struct {
quantile float64
epsilon float64
}
func targetMapToSlice(targetMap map[float64]float64) []target {
targets := make([]target, 0, len(targetMap))
for quantile, epsilon := range targetMap {
t := target{
quantile: quantile,
epsilon: epsilon,
}
targets = append(targets, t)
}
return targets
}
// Stream computes quantiles for a stream of float64s. It is not thread-safe by
// design. Take care when using across multiple goroutines.
type Stream struct {
@@ -157,7 +133,7 @@ func (s *Stream) Query(q float64) float64 {
if l == 0 {
return 0
}
i := int(math.Ceil(float64(l) * q))
i := int(float64(l) * q)
if i > 0 {
i -= 1
}