util

package
v0.0.0-...-7b3a75c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2017 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FloatSlidingWindow

type FloatSlidingWindow interface {
	// Add a value to the end of the queue. On overflow returns true and the
	// oldest value, which is also removed from the buffer. Otherwise
	// returns (false, _).
	Push(value float64) (bool, float64)

	// Returns the elements in the buffer, ordered by time of insertion
	// (oldest first).
	Contents() []float64

	// Returns a pointer to the most recently added element. The pointer can
	// be used to modify the last element. It is only valid until the next
	// call to Push(). Return nil if called on an empty buffer.
	Head() *float64
}

FloatSlidingWindow is a buffer with a fixed capacity. Elements are inserted/removed in the FIFO order. Elements are removed from the buffer only when it runs out of capacity and a new element is inserted.

func NewFloatSlidingWindow

func NewFloatSlidingWindow(size int) FloatSlidingWindow

NewFloatSlidingWindow returns a new instance of FloatSlidingWindowImpl with a given size.

type Histogram

type Histogram interface {
	// Returns an approximation of the given percentile of the distribution.
	// Note: the argument passed to Percentile() is a number between
	// 0 and 1. For example 0.5 corresponds to the median and 0.9 to the
	// 90th percentile.
	// If the histogram is empty, Percentile() returns 0.0.
	Percentile(percentile float64) float64

	// Add a sample with a given value and weight.
	AddSample(value float64, weight float64)

	// Remove a sample with a given value and weight. Note that the total
	// weight of samples with a given value cannot be negative.
	SubtractSample(value float64, weight float64)

	// Returns true if the histogram is empty.
	IsEmpty() bool
}

Histogram represents an approximate distribution of some variable.

func NewHistogram

func NewHistogram(options HistogramOptions) Histogram

NewHistogram returns a new Histogram instance using given options.

type HistogramOptions

type HistogramOptions interface {
	// Returns the number of buckets in the histogram.
	NumBuckets() int
	// Returns the index of the bucket to which the given value falls.
	// If the value is outside of the range covered by the histogram, it
	// returns the closest bucket (either the first or the last one).
	FindBucket(value float64) int
	// Returns the start of the bucket with a given index. If the index is
	// outside the [0..NumBuckets() - 1] range, the result is undefined.
	GetBucketStart(bucket int) float64
	// Returns the minimum weight for a bucket to be considered non-empty.
	Epsilon() float64
}

HistogramOptions define the number and size of buckets of a histogram.

func NewExponentialHistogramOptions

func NewExponentialHistogramOptions(
	maxValue float64, firstBucketSize float64, ratio float64, epsilon float64) (HistogramOptions, error)

NewExponentialHistogramOptions returns HistogramOptions describing a histogram with exponentially growing bucket boundaries. The first bucket covers the range [0..firstBucketSize). Consecutive buckets are of the form [x(n)..x(n) * ratio) for n = 1 .. numBuckets - 1. The last bucket start is larger or equal to maxValue. Requires maxValue > 0, firstBucketSize > 0, ratio > 1, epsilon > 0.

func NewLinearHistogramOptions

func NewLinearHistogramOptions(
	maxValue float64, bucketSize float64, epsilon float64) (HistogramOptions, error)

NewLinearHistogramOptions returns HistogramOptions describing a histogram with a given number of fixed-size buckets, with the first bucket start at 0.0 and the last bucket start larger or equal to maxValue. Requires maxValue > 0, bucketSize > 0, epsilon > 0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL