Remove Stream.Min/Max ...
These are best calculated by the user as items are inserted. These can't be
represented accurately in Samples.
Blake Mizerany
11 years ago
22 | 22 |
fmt.Println("perc50:", q.Query(0.50))
|
23 | 23 |
fmt.Println("perc90:", q.Query(0.90))
|
24 | 24 |
fmt.Println("perc99:", q.Query(0.99))
|
25 | |
fmt.Println("min:", q.Min())
|
26 | |
fmt.Println("max:", q.Max())
|
27 | 25 |
fmt.Println("count:", q.Count())
|
28 | 26 |
// Output:
|
29 | 27 |
// perc50: 5
|
30 | 28 |
// perc90: 14
|
31 | 29 |
// perc99: 40
|
32 | |
// min: 1
|
33 | |
// max: 1545
|
34 | 30 |
// count: 2388
|
35 | 31 |
}
|
36 | 32 |
|
111 | 111 |
q []float64
|
112 | 112 |
n float64
|
113 | 113 |
l *list.List
|
114 | |
max float64
|
115 | 114 |
}
|
116 | 115 |
|
117 | 116 |
func (s *stream) Init() {
|
|
151 | 150 |
var r float64
|
152 | 151 |
e := s.l.Front()
|
153 | 152 |
return func(v, w float64) {
|
154 | |
if v > s.max {
|
155 | |
s.max = v
|
156 | |
}
|
157 | |
|
158 | 153 |
for ; e != nil; e = e.Next() {
|
159 | 154 |
c := e.Value.(*Sample)
|
160 | 155 |
if c.Value > v {
|
|
225 | 220 |
}
|
226 | 221 |
return samples
|
227 | 222 |
}
|
228 | |
|
229 | |
// Min returns the minimum value observed in the stream.
|
230 | |
func (s *stream) Min() float64 {
|
231 | |
if e := s.l.Front(); e != nil {
|
232 | |
return e.Value.(*Sample).Value
|
233 | |
}
|
234 | |
return math.NaN()
|
235 | |
}
|
236 | |
|
237 | |
// Max returns the maximum value observed in the stream within the error epsilon.
|
238 | |
func (s *stream) Max() float64 {
|
239 | |
if s.l.Len() > 0 {
|
240 | |
return s.max
|
241 | |
}
|
242 | |
return math.NaN()
|
243 | |
}
|