quantile

package module
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 14 Imported by: 6 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package quantile provides a quantile sketch.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNonMonotonicBoundaries is returned when the boundaries of an explicit bucket histogram are not monotonic.
	ErrNonMonotonicBoundaries = "explicit bucket histogram: non-monotonic boundaries"
)

Functions

This section is empty.

Types

type Agent

type Agent struct {
	Buf      []Key
	CountBuf []KeyCount
	Sketch   Sketch
}

An Agent sketch is an insert optimized version of the sketch for use in the datadog-agent.

func (*Agent) Finish

func (a *Agent) Finish() *Sketch

Finish flushes any pending inserts and returns a deep copy of the sketch.

func (*Agent) Insert

func (a *Agent) Insert(v float64, sampleRate float64)

Insert v into the sketch.

func (*Agent) InsertInterpolate

func (a *Agent) InsertInterpolate(lower float64, upper float64, count uint) error

InsertInterpolate linearly interpolates a count from the given lower to upper bounds

func (*Agent) IsEmpty

func (a *Agent) IsEmpty() bool

IsEmpty returns true if the sketch is empty

func (*Agent) Reset

func (a *Agent) Reset()

Reset the agent sketch to the empty state.

type Bound added in v0.71.0

type Bound struct {
	// Key is the quantized value of the bound.
	Key Key
	Low float64 // Low is the lower bound of the range.
}

Bound is a quantized value and its corresponding lower bound.

type Config

type Config struct {
	// contains filtered or unexported fields
}

A Config struct is passed around to many sketches (read-only).

func Default

func Default() *Config

Default returns the default config.

func NewConfig

func NewConfig(eps, min float64, binLimit int) (*Config, error)

NewConfig creates a config object with. TODO|DOC: describe params

func (*Config) MaxCount

func (c *Config) MaxCount() int

MaxCount returns the max number of values you can insert. This is limited by using a uint16 for bin.n

type DDSketchBinGenerator added in v0.71.0

type DDSketchBinGenerator struct {
	// Config is the configuration for the sketch.
	Config   *Config
	Bounds   []Bound
	BoundMap map[Key]*Bound
}

DDSketchBinGenerator is a generator for DDSketch bounds.

func NewDDSketchBinGenerator added in v0.71.0

func NewDDSketchBinGenerator(config *Config) *DDSketchBinGenerator

NewDDSketchBinGenerator creates a new DDSketchBinGenerator for the given config.

func NewDDSketchBinGeneratorForAgent added in v0.71.0

func NewDDSketchBinGeneratorForAgent() *DDSketchBinGenerator

NewDDSketchBinGeneratorForAgent creates a new DDSketchBinGenerator for the agent.

func (*DDSketchBinGenerator) GetBound added in v0.71.0

func (g *DDSketchBinGenerator) GetBound(key Key) (*Bound, bool)

GetBound returns the bound for the given key.

func (*DDSketchBinGenerator) GetBounds added in v0.71.0

func (g *DDSketchBinGenerator) GetBounds() []Bound

GetBounds returns the bounds for the DDSketchBinGenerator.

func (*DDSketchBinGenerator) GetKeyForValue added in v0.71.0

func (g *DDSketchBinGenerator) GetKeyForValue(value float64) Key

GetKeyForValue returns the key for the given value.

type Key

type Key int16

A Key represents a quantized version of a float64. See Config for more details

func InfKey

func InfKey(sign int) Key

InfKey returns the Key for +Inf if sign >= 0, -Inf if sign < 0.

func (Key) IsInf

func (k Key) IsInf() bool

IsInf returns true if the key represents +/-Inf

func (Key) String

func (k Key) String() string

type KeyCount

type KeyCount struct {
	// contains filtered or unexported fields
}

A KeyCount represents a Key and an associated count

type Sketch

type Sketch struct {
	Basic summary.Summary `json:"summary"`
	// contains filtered or unexported fields
}

A Sketch for tracking quantiles The serialized JSON of Sketch contains the summary only Bins are not included.

func ConvertDDSketchIntoSketch

func ConvertDDSketchIntoSketch(inputSketch *ddsketch.DDSketch) (*Sketch, error)

ConvertDDSketchIntoSketch converts a DDSketch into a Sketch, by first converting the DDSketch into a new DDSketch with a mapping that's compatible with Sketch parameters, then creating the Sketch by copying the DDSketch bins to the Sketch store.

func (*Sketch) ApproxEquals

func (s *Sketch) ApproxEquals(o *Sketch, e float64) bool

ApproxEquals checks if s and o are equivalent, with e error allowed for Sum and Average

func (*Sketch) BasicStats added in v0.78.0

func (s *Sketch) BasicStats() (cnt int64, min, max, sum, avg float64)

BasicStats returns the five summary fields used by the serializer. It implements the metrics.SketchData interface.

func (*Sketch) Cols

func (s *Sketch) Cols() (k []int32, n []uint32)

Cols returns an array of k and n.

func (*Sketch) Copy

func (s *Sketch) Copy() *Sketch

Copy returns a deep copy

func (*Sketch) CopyTo

func (s *Sketch) CopyTo(dst *Sketch)

CopyTo makes a deep copy of this sketch into dst.

func (*Sketch) Equals

func (s *Sketch) Equals(o *Sketch) bool

Equals returns true if s and o are equivalent.

func (*Sketch) GetRawBins

func (s *Sketch) GetRawBins() (int, string)

GetRawBins return raw bins information as string

func (*Sketch) Insert

func (s *Sketch) Insert(c *Config, vals ...float64)

Insert a single value into the sketch. NOTE: InsertMany is much more efficient.

func (*Sketch) InsertMany

func (s *Sketch) InsertMany(c *Config, values []float64)

InsertMany values into the sketch.

func (*Sketch) MemSize

func (s *Sketch) MemSize() (used, allocated int)

MemSize returns memory use in bytes:

used: uses len(bins)
allocated: uses cap(bins)

func (*Sketch) Merge

func (s *Sketch) Merge(c *Config, o *Sketch)

Merge o into s, without mutating o.

func (*Sketch) Quantile

func (s *Sketch) Quantile(c *Config, q float64) float64

Quantile returns v such that s.count*q items are <= v.

Special cases are:

	Quantile(c, q <= 0)  = min
 Quantile(c, q >= 1)  = max

func (*Sketch) Reset

func (s *Sketch) Reset()

Reset sketch to its empty state.

func (*Sketch) String

func (s *Sketch) String() string

Directories

Path Synopsis
sketchtest module
Package summary provides a summary of a quantile sketch.
Package summary provides a summary of a quantile sketch.

Jump to

Keyboard shortcuts

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