vendor: bump beorn7/perks v1.0.1
full diff: 4c0e84591b...v1.0.1
- beorn7/perks#3 Avoid iterating on maps
    - Speed up InsertTargeted* functions by at least 2x by avoiding iterating on maps.
- beorn7/perks#4 Fixed format error
- Use 1000000 instead of 1e6 for int constant
- Add go module support
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
			
			
This commit is contained in:
		
							
								
								
									
										3
									
								
								vendor/github.com/beorn7/perks/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								vendor/github.com/beorn7/perks/go.mod
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
module github.com/beorn7/perks
 | 
			
		||||
 | 
			
		||||
go 1.11
 | 
			
		||||
							
								
								
									
										34
									
								
								vendor/github.com/beorn7/perks/quantile/stream.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										34
									
								
								vendor/github.com/beorn7/perks/quantile/stream.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -77,15 +77,20 @@ 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(targets map[float64]float64) *Stream {
 | 
			
		||||
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(s *stream, r float64) float64 {
 | 
			
		||||
		var m = math.MaxFloat64
 | 
			
		||||
		var f float64
 | 
			
		||||
		for quantile, epsilon := range targets {
 | 
			
		||||
			if quantile*s.n <= r {
 | 
			
		||||
				f = (2 * epsilon * r) / quantile
 | 
			
		||||
		for _, t := range targets {
 | 
			
		||||
			if t.quantile*s.n <= r {
 | 
			
		||||
				f = (2 * t.epsilon * r) / t.quantile
 | 
			
		||||
			} else {
 | 
			
		||||
				f = (2 * epsilon * (s.n - r)) / (1 - quantile)
 | 
			
		||||
				f = (2 * t.epsilon * (s.n - r)) / (1 - t.quantile)
 | 
			
		||||
			}
 | 
			
		||||
			if f < m {
 | 
			
		||||
				m = f
 | 
			
		||||
@@ -96,6 +101,25 @@ func NewTargeted(targets 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 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user