[ Alexandre Viau ]
[ Debian Janitor ]
New upstream release.
Debian Janitor
4 years ago
0 | |
golang-github-beorn7-perks (0.0~git20160804.0.4c0e845-2) UNRELEASED; urgency=medium
|
|
0 |
golang-github-beorn7-perks (1.0.0-1) UNRELEASED; urgency=medium
|
1 | 1 |
|
|
2 |
[ Alexandre Viau ]
|
2 | 3 |
* Point Vcs-* urls to salsa.debian.org.
|
3 | 4 |
|
4 | |
-- Alexandre Viau <aviau@debian.org> Mon, 02 Apr 2018 14:52:51 -0400
|
|
5 |
[ Debian Janitor ]
|
|
6 |
* New upstream release.
|
|
7 |
|
|
8 |
-- Debian Janitor <janitor@jelmer.uk> Fri, 10 May 2019 10:44:10 +0000
|
5 | 9 |
|
6 | 10 |
golang-github-beorn7-perks (0.0~git20160804.0.4c0e845-1) unstable; urgency=medium
|
7 | 11 |
|
|
0 |
module github.com/beorn7/perks
|
|
1 |
|
|
2 |
go 1.12
|
5 | 5 |
)
|
6 | 6 |
|
7 | 7 |
func TestHistogram(t *testing.T) {
|
8 | |
const numPoints = 1e6
|
|
8 |
const numPoints = 1000000
|
9 | 9 |
const maxBins = 3
|
10 | 10 |
|
11 | 11 |
h := New(maxBins)
|
76 | 76 |
// is guaranteed to be within (Quantile±Epsilon).
|
77 | 77 |
//
|
78 | 78 |
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
|
79 | |
func NewTargeted(targets map[float64]float64) *Stream {
|
|
79 |
func NewTargeted(targetMap map[float64]float64) *Stream {
|
|
80 |
// Convert map to slice to avoid slow iterations on a map.
|
|
81 |
// ƒ is called on the hot path, so converting the map to a slice
|
|
82 |
// beforehand results in significant CPU savings.
|
|
83 |
targets := targetMapToSlice(targetMap)
|
|
84 |
|
80 | 85 |
ƒ := func(s *stream, r float64) float64 {
|
81 | 86 |
var m = math.MaxFloat64
|
82 | 87 |
var f float64
|
83 | |
for quantile, epsilon := range targets {
|
84 | |
if quantile*s.n <= r {
|
85 | |
f = (2 * epsilon * r) / quantile
|
|
88 |
for _, t := range targets {
|
|
89 |
if t.quantile*s.n <= r {
|
|
90 |
f = (2 * t.epsilon * r) / t.quantile
|
86 | 91 |
} else {
|
87 | |
f = (2 * epsilon * (s.n - r)) / (1 - quantile)
|
|
92 |
f = (2 * t.epsilon * (s.n - r)) / (1 - t.quantile)
|
88 | 93 |
}
|
89 | 94 |
if f < m {
|
90 | 95 |
m = f
|
|
93 | 98 |
return m
|
94 | 99 |
}
|
95 | 100 |
return newStream(ƒ)
|
|
101 |
}
|
|
102 |
|
|
103 |
type target struct {
|
|
104 |
quantile float64
|
|
105 |
epsilon float64
|
|
106 |
}
|
|
107 |
|
|
108 |
func targetMapToSlice(targetMap map[float64]float64) []target {
|
|
109 |
targets := make([]target, 0, len(targetMap))
|
|
110 |
|
|
111 |
for quantile, epsilon := range targetMap {
|
|
112 |
t := target{
|
|
113 |
quantile: quantile,
|
|
114 |
epsilon: epsilon,
|
|
115 |
}
|
|
116 |
targets = append(targets, t)
|
|
117 |
}
|
|
118 |
|
|
119 |
return targets
|
96 | 120 |
}
|
97 | 121 |
|
98 | 122 |
// Stream computes quantiles for a stream of float64s. It is not thread-safe by
|