29 | 29 |
// Samples represents a slice of samples. It implements sort.Interface.
|
30 | 30 |
type Samples []Sample
|
31 | 31 |
|
32 | |
func (a Samples) Len() int {
|
33 | |
return len(a)
|
34 | |
}
|
35 | |
|
36 | |
func (a Samples) Less(i, j int) bool {
|
37 | |
return a[i].Value < a[j].Value
|
38 | |
}
|
39 | |
|
40 | |
func (a Samples) Swap(i, j int) {
|
41 | |
a[i], a[j] = a[j], a[i]
|
42 | |
}
|
|
32 |
func (a Samples) Len() int { return len(a) }
|
|
33 |
func (a Samples) Less(i, j int) bool { return a[i].Value < a[j].Value }
|
|
34 |
func (a Samples) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
43 | 35 |
|
44 | 36 |
type invariant func(s *stream, r float64) float64
|
45 | 37 |
|
46 | 38 |
// NewBiased returns an initialized Stream for high-biased quantiles (e.g.
|
47 | |
// 50th, 90th, 99th) not known a priori with finer error guarantees for the
|
|
39 |
// 50th, 90th, 99th) not known a priori with finer error guarantees for the
|
48 | 40 |
// higher ranks of the data distribution.
|
49 | 41 |
// See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
|
50 | 42 |
func NewBiased() *Stream {
|
|
111 | 103 |
func (s *Stream) Query(q float64) float64 {
|
112 | 104 |
if !s.flushed() {
|
113 | 105 |
// Fast path when there hasn't been enough data for a flush;
|
114 | |
// this also yeilds better accuracy for small sets of data.
|
|
106 |
// this also yields better accuracy for small sets of data.
|
115 | 107 |
l := len(s.b)
|
116 | 108 |
if l == 0 {
|
117 | 109 |
return 0
|