keep real max
Blake Mizerany
11 years ago
40 | 40 | q []float64 |
41 | 41 | n float64 |
42 | 42 | l *list.List |
43 | max float64 | |
43 | 44 | } |
44 | 45 | |
45 | 46 | // New returns an initialized stream. |
85 | 86 | var r float64 |
86 | 87 | e := qt.l.Front() |
87 | 88 | return func(v, w float64) { |
89 | if v > qt.max { | |
90 | qt.max = v | |
91 | } | |
92 | ||
88 | 93 | for ; e != nil; e = e.Next() { |
89 | 94 | c := e.Value.(*Sample) |
90 | 95 | if c.Value > v { |
164 | 169 | |
165 | 170 | // Max returns the maximum value observed in the stream within the error epsilon. |
166 | 171 | func (qt *stream) Max() float64 { |
167 | if e := qt.l.Back(); e != nil { | |
168 | return e.Value.(*Sample).Value | |
172 | if qt.l.Len() > 0 { | |
173 | return qt.max | |
169 | 174 | } |
170 | 175 | return math.NaN() |
171 | 176 | } |