type Sample … type Samples … func (a Samples) Len() int { … } func (a Samples) Less(i, j int) bool { … } func (a Samples) Swap(i, j int) { … } type invariant … // NewLowBiased returns an initialized Stream for low-biased quantiles // (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but // error guarantees can still be given even for the lower ranks of the data // distribution. // // The provided epsilon is a relative error, i.e. the true quantile of a value // returned by a query is guaranteed to be within (1±Epsilon)*Quantile. // // See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error // properties. func NewLowBiased(epsilon float64) *Stream { … } // NewHighBiased returns an initialized Stream for high-biased quantiles // (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but // error guarantees can still be given even for the higher ranks of the data // distribution. // // The provided epsilon is a relative error, i.e. the true quantile of a value // returned by a query is guaranteed to be within 1-(1±Epsilon)*(1-Quantile). // // See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error // properties. func NewHighBiased(epsilon float64) *Stream { … } // NewTargeted returns an initialized Stream concerned with a particular set of // quantile values that are supplied a priori. Knowing these a priori reduces // space and computation time. The targets map maps the desired quantiles to // their absolute errors, i.e. the true quantile of a value returned by a query // is guaranteed to be within (Quantile±Epsilon). // // See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties. func NewTargeted(targetMap map[float64]float64) *Stream { … } type target … func targetMapToSlice(targetMap map[float64]float64) []target { … } type Stream … func newStream(ƒ invariant) *Stream { … } // Insert inserts v into the stream. func (s *Stream) Insert(v float64) { … } func (s *Stream) insert(sample Sample) { … } // Query returns the computed qth percentiles value. If s was created with // NewTargeted, and q is not in the set of quantiles provided a priori, Query // will return an unspecified result. func (s *Stream) Query(q float64) float64 { … } // Merge merges samples into the underlying streams samples. This is handy when // merging multiple streams from separate threads, database shards, etc. // // ATTENTION: This method is broken and does not yield correct results. The // underlying algorithm is not capable of merging streams correctly. func (s *Stream) Merge(samples Samples) { … } // Reset reinitializes and clears the list reusing the samples buffer memory. func (s *Stream) Reset() { … } // Samples returns stream samples held by s. func (s *Stream) Samples() Samples { … } // Count returns the total number of samples observed in the stream // since initialization. func (s *Stream) Count() int { … } func (s *Stream) flush() { … } func (s *Stream) maybeSort() { … } func (s *Stream) flushed() bool { … } type stream … func (s *stream) reset() { … } func (s *stream) insert(v float64) { … } func (s *stream) merge(samples Samples) { … } func (s *stream) count() int { … } func (s *stream) query(q float64) float64 { … } func (s *stream) compress() { … } func (s *stream) samples() Samples { … }