▹ Example (MergeMultipleStreams)
▹ Example (Simple)
▹ Example (Window)
type Sample struct { Value float64 `json:",string"` Width float64 `json:",string"` Delta float64 `json:",string"` }
Sample holds an observed value and meta information for compression. JSON tags have been added for convenience.
type Samples []Sample
Samples represents a slice of samples. It implements sort.Interface.
func (a Samples) Len() int
func (a Samples) Less(i, j int) bool
func (a Samples) Swap(i, j int)
type Stream struct {
// contains filtered or unexported fields
}
Stream computes quantiles for a stream of float64s. It is not thread-safe by design. Take care when using across multiple goroutines.
func NewHighBiased(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 NewLowBiased(epsilon float64) *Stream
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 NewTargeted(targets map[float64]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 (s *Stream) Count() int
Count returns the total number of samples observed in the stream since initialization.
func (s *Stream) Insert(v float64)
Insert inserts v into the stream.
func (s *Stream) Merge(samples Samples)
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) Query(q float64) float64
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) Reset()
Reset reinitializes and clears the list reusing the samples buffer memory.
func (s *Stream) Samples() Samples
Samples returns stream samples held by s.