tdigest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultK = 200
)

Variables

View Source
var (
	ErrEmpty       = errors.New("operation is undefined for an empty sketch")
	ErrNaN         = errors.New("operation is undefined for NaN")
	ErrInfinity    = errors.New("operation is undefined for Infinity")
	ErrInvalidRank = errors.New("normalized rank must be between 0 and 1 inclusive")
	ErrInvalidK    = errors.New("k must be at least 10")
)

Functions

func EncodeDouble

func EncodeDouble(sketch *Double, withBuffer bool) ([]byte, error)

EncodeDouble encodes a Double to bytes.

Types

type Double

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

Double provides an implementation of t-Digest double precision type for estimating quantiles and ranks. This implementation is based on the paper: Ted Dunning, Otmar Ertl. "Extremely Accurate Quantiles Using t-Digests" and the reference implementation: https://github.com/tdunning/t-digest NOTE: This implementation is similar to MergingDigest in the above Java implementation

func DecodeDouble

func DecodeDouble(data []byte) (*Double, error)

DecodeDouble deserializes bytes into a Double.

func NewDouble

func NewDouble(k uint16) (*Double, error)

NewDouble creates a new Double with the given compression parameter k.

func (*Double) CDF

func (d *Double) CDF(splitPoints []float64) ([]float64, error)

CDF returns an approximation to the Cumulative Distribution Function (CDF) which is the cumulative analog of the PMF of the input stream.

func (*Double) IsEmpty

func (d *Double) IsEmpty() bool

IsEmpty returns true if the t-Digest has not seen any data

func (*Double) K

func (d *Double) K() uint16

K returns the compression parameter k

func (*Double) MaxValue

func (d *Double) MaxValue() (float64, error)

MaxValue returns the maximum value seen by the t-Digest

func (*Double) Merge

func (d *Double) Merge(other *Double) error

Merge merges another Double into this one

func (*Double) MinValue

func (d *Double) MinValue() (float64, error)

MinValue returns the minimum value seen by the t-Digest

func (*Double) PMF

func (d *Double) PMF(splitPoints []float64) ([]float64, error)

PMF returns an approximation to the Probability Mass Function (PMF) of the input stream.

func (*Double) Quantile

func (d *Double) Quantile(rank float64) (float64, error)

Quantile computes the approximate quantile value corresponding to the given normalized rank

func (*Double) Rank

func (d *Double) Rank(value float64) (float64, error)

Rank computes the approximate normalized rank of the given value

func (*Double) SerializedSizeBytes

func (d *Double) SerializedSizeBytes(withBuffer bool) int

SerializedSizeBytes computes the serialized size in bytes of the t-Digest.

func (*Double) String

func (d *Double) String(shouldPrintCentroids bool) string

String returns a human-readable summary of the t-Digest

func (*Double) TotalWeight

func (d *Double) TotalWeight() uint64

TotalWeight returns the total weight of all values

func (*Double) Update

func (d *Double) Update(value float64) error

Update adds a value to the t-Digest. Returns ErrNaN if the value is NaN. Returns ErrInfinity if the value is positive or negative infinity.

type DoubleDecoder

type DoubleDecoder struct{}

DoubleDecoder decodes a Double from the given reader.

func NewDoubleDecoder

func NewDoubleDecoder() DoubleDecoder

NewDoubleDecoder creates and returns a new instance of DoubleDecoder.

func (*DoubleDecoder) Decode

func (d *DoubleDecoder) Decode(r io.Reader) (*Double, error)

Decode decodes t-Digest double precision type from a given stream.

type DoubleEncoder

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

DoubleEncoder encodes a Double to bytes.

func NewDoubleEncoder

func NewDoubleEncoder(w io.Writer, withBuffer bool) DoubleEncoder

NewDoubleEncoder creates a new encoder.

func (*DoubleEncoder) Encode

func (enc *DoubleEncoder) Encode(sketch *Double) error

Encode encodes a Double to bytes.

Jump to

Keyboard shortcuts

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