Codebase list golang-github-beorn7-perks / e3edcea
fix flushed Samples Blake Mizerany 10 years ago
2 changed file(s) with 14 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
106106 // NewTargeted, and q is not in the set of quantiles provided a priori, Query
107107 // will return an unspecified result.
108108 func (s *Stream) Query(q float64) float64 {
109 if s.flushed() {
109 if !s.flushed() {
110110 // Fast path when there hasn't been enough data for a flush;
111111 // this also yeilds better accuracy for small sets of data.
112112 l := len(s.b)
141141 if !s.flushed() {
142142 return s.b
143143 }
144 s.flush()
145 s.compress()
144146 return s.stream.samples()
145147 }
146148
157159 }
158160
159161 func (s *Stream) flushed() bool {
160 return s.stream.l.Len() == 0
162 return s.stream.l.Len() > 0
161163 }
162164
163165 type stream struct {
9797 }
9898 }
9999
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
100110 func TestUncompressedOne(t *testing.T) {
101111 q := NewTargeted(0.90)
102112 q.Insert(3.14)