fix flushed Samples
Blake Mizerany
10 years ago
106 | 106 |
// NewTargeted, and q is not in the set of quantiles provided a priori, Query
|
107 | 107 |
// will return an unspecified result.
|
108 | 108 |
func (s *Stream) Query(q float64) float64 {
|
109 | |
if s.flushed() {
|
|
109 |
if !s.flushed() {
|
110 | 110 |
// Fast path when there hasn't been enough data for a flush;
|
111 | 111 |
// this also yeilds better accuracy for small sets of data.
|
112 | 112 |
l := len(s.b)
|
|
141 | 141 |
if !s.flushed() {
|
142 | 142 |
return s.b
|
143 | 143 |
}
|
|
144 |
s.flush()
|
|
145 |
s.compress()
|
144 | 146 |
return s.stream.samples()
|
145 | 147 |
}
|
146 | 148 |
|
|
157 | 159 |
}
|
158 | 160 |
|
159 | 161 |
func (s *Stream) flushed() bool {
|
160 | |
return s.stream.l.Len() == 0
|
|
162 |
return s.stream.l.Len() > 0
|
161 | 163 |
}
|
162 | 164 |
|
163 | 165 |
type stream struct {
|
97 | 97 |
}
|
98 | 98 |
}
|
99 | 99 |
|
|
100 |
func TestUncompressedSamples(t *testing.T) {
|
|
101 |
q := NewTargeted(0.99)
|
|
102 |
for i := 1; i <= 100; i++ {
|
|
103 |
q.Insert(float64(i))
|
|
104 |
}
|
|
105 |
if g := q.Samples().Len(); g != 100 {
|
|
106 |
t.Errorf("want count 100, got %d", g)
|
|
107 |
}
|
|
108 |
}
|
|
109 |
|
100 | 110 |
func TestUncompressedOne(t *testing.T) {
|
101 | 111 |
q := NewTargeted(0.90)
|
102 | 112 |
q.Insert(3.14)
|