req

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmpty = errors.New("operation is undefined for an empty sketch")
)

Functions

func ComputeRSE

func ComputeRSE(k int, rank float64, isHighRankAccuracyMode bool, n int64) float64

ComputeRSE returns an a priori estimate of relative standard error (ComputeRSE, expressed as a number in [0,1]). Derived from Lemma 12 in https://arxiv.org/abs/2004.01668v2, but the constant factors were adjusted based on empirical measurements. K is the sketch's k. Rank is the normalized rank, in [0,1]. isHighRankAccuracyMode is true if the sketch is configured for high rank accuracy. N is the total number of items in the stream.

Types

type ConfidenceOptionFunc

type ConfidenceOptionFunc func(*confidenceOptions)

ConfidenceOptionFunc is a function type that configures confidence interval options.

func WithNumStdDev

func WithNumStdDev(n int) ConfidenceOptionFunc

WithNumStdDev sets the number of standard deviations to use for confidence intervals.

type Item

type Item struct {
	Quantile float32
	Weight   int64
}

Item represents a quantile value and its associated weight retained by the sketch.

type SearchCriteriaOptionFunc

type SearchCriteriaOptionFunc func(*searchCriteria)

SearchCriteriaOptionFunc defines a function type used to configure or modify a searchCriteria instance.

func WithExclusiveSearch

func WithExclusiveSearch() SearchCriteriaOptionFunc

WithExclusiveSearch creates a SearchCriteriaOptionFunc that sets the search criteria to be exclusive.

type Sketch

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

func NewSketch

func NewSketch(options ...SketchOptionFunc) (*Sketch, error)

func (*Sketch) All

func (s *Sketch) All() []Item

All returns all retained items of the sketch.

func (*Sketch) CDF

func (s *Sketch) CDF(splitPoints []float32, isInclusive bool) ([]float64, error)

CDF is equivalent of NumericSortedView CDF function.

func (*Sketch) CompactorDetailString

func (s *Sketch) CompactorDetailString(showAllData bool) string

CompactorDetailString returns a string representation of the compactors in the sketch. Each compactor string is prepended by the compactor lgWeight, the current number of retained quantiles of the compactor and the current nominal capacity of the compactor.

func (*Sketch) IsEmpty

func (s *Sketch) IsEmpty() bool

IsEmpty checks if the sketch contains no data and returns true if it is empty, otherwise false.

func (*Sketch) IsEstimationMode

func (s *Sketch) IsEstimationMode() bool

IsEstimationMode returns true if the sketch is in estimation mode.

func (*Sketch) IsHighRankAccuracyMode

func (s *Sketch) IsHighRankAccuracyMode() bool

IsHighRankAccuracyMode returns whether the sketch is in high rank accuracy mode. If true, the high ranks are prioritized for better accuracy. If not, low ranks are prioritized for better accuracy.

func (*Sketch) K

func (s *Sketch) K() int

K returns the k parameter which controls the accuracy of the sketch and its memory space usage.

func (*Sketch) MaxItem

func (s *Sketch) MaxItem() (float32, error)

MaxItem retrieves the maximum item in the sketch. Returns an error if the sketch is empty.

func (*Sketch) Merge

func (s *Sketch) Merge(other *Sketch) error

Merge merges another sketch into this one. The other sketch is not modified.

func (*Sketch) MinItem

func (s *Sketch) MinItem() (float32, error)

MinItem retrieves the minimum item in the sketch. Returns an error if the sketch is empty.

func (*Sketch) N

func (s *Sketch) N() int64

N returns the total number of items in the sketch.

func (*Sketch) NumRetained

func (s *Sketch) NumRetained() int

NumRetained returns the number of quantiles retained by the sketch.

func (*Sketch) PMF

func (s *Sketch) PMF(splitPoints []float32, opts ...SearchCriteriaOptionFunc) ([]float64, error)

PMF is the equivalent of the NumericSortedView PMF function. the default option is inclusive.

func (*Sketch) Quantile

func (s *Sketch) Quantile(normRank float64, opts ...SearchCriteriaOptionFunc) (float32, error)

Quantile gets the approximate quantile of the given normalized rank. normRank is the normalized rank in the range [0.0, 1.0]. If isInclusive is true, rank includes all the quantiles less than or equal to the quantile directly corresponding to the given rank. If not, rank includes all the quantiles less than the quantile directly corresponding to the given rank. The default option is inclusive.

func (*Sketch) QuantileLowerBound

func (s *Sketch) QuantileLowerBound(
	rank float64, opts ...ConfidenceOptionFunc,
) (float32, error)

QuantileLowerBound returns the lower bound of the quantile confidence interval in which the quantile of the given rank exists. numStdDev is the number of standard deviations. Must be 1, 2, or 3. default numStdDev is 2. When numStdDev is 2, the approximate probability that the true quantile is within the confidence interval specified by the upper and lower quantile bounds for this sketch is 0.95.

func (*Sketch) QuantileUpperBound

func (s *Sketch) QuantileUpperBound(
	rank float64, opts ...ConfidenceOptionFunc,
) (float32, error)

QuantileUpperBound returns the upper bound of the quantile confidence interval in which the quantile of the given rank exists. numStdDev is the number of standard deviations. Must be 1, 2, or 3. default numStdDev is 2. When numStdDev is 2, the approximate probability that the true quantile is within the confidence interval specified by the upper and lower quantile bounds for this sketch is 0.95.

func (*Sketch) Quantiles

func (s *Sketch) Quantiles(ranks []float64, opts ...SearchCriteriaOptionFunc) ([]float32, error)

Quantiles gets quantiles from the given array of normalized ranks. ranks is the normalized ranks, each of which must be in the valid interval [0.0, 1.0]. The default option is inclusive search.

func (*Sketch) Rank

func (s *Sketch) Rank(quantile float32, opts ...SearchCriteriaOptionFunc) (float64, error)

Rank returns normalized rank corresponding to the given quantile and search criterion. The default option is inclusive search.

func (*Sketch) RankLowerBound

func (s *Sketch) RankLowerBound(
	rank float64, opts ...ConfidenceOptionFunc,
) (float64, error)

RankLowerBound returns the approximate lower bound of a rank confidence interval which the true rank of the given rank exists. rank should be in the 0 to 1.0. numStdDev is the number of standard deviations. Must be 1, 2, or 3. default numStdDev is 2. When numStdDev is 2, the approximate probability that the true quantile is within the confidence interval specified by the upper and lower quantile bounds for this sketch is 0.95.

func (*Sketch) RankUpperBound

func (s *Sketch) RankUpperBound(
	rank float64, opts ...ConfidenceOptionFunc,
) (float64, error)

RankUpperBound returns the approximate upper bound of the rank confidence interval in which the true rank of the given rank exists. rank should be in the 0 to 1.0. numStdDev is the number of standard deviations. Must be 1, 2, or 3. default numStdDev is 2. When numStdDev is 2, the approximate probability that the true quantile is within the confidence interval specified by the upper and lower quantile bounds for this sketch is 0.95.

func (*Sketch) Ranks

func (s *Sketch) Ranks(quantiles []float32, opts ...SearchCriteriaOptionFunc) ([]float64, error)

Ranks returns normalized ranks corresponding to the given quantiles and search criterion. The default option is inclusive.

func (*Sketch) Reset

func (s *Sketch) Reset()

Reset the sketch to the empty state.

func (*Sketch) SortedView

func (s *Sketch) SortedView() (*quantilecommon.NumericSortedView[float32], error)

SortedView returns a sorted view of the data retained by the sketch, or an error if refreshing the view fails.

func (*Sketch) String

func (s *Sketch) String() string

String returns a string representation of the sketch.

func (*Sketch) Update

func (s *Sketch) Update(item float32) error

Update updates this sketch with the given item. NaN are ignored.

type SketchOptionFunc

type SketchOptionFunc func(*Sketch)

func WithHighRankAccuracyMode

func WithHighRankAccuracyMode(isHRAMode bool) SketchOptionFunc

WithHighRankAccuracyMode sets the high rank accuracy mode for the Sketch.

func WithK

func WithK(k int) SketchOptionFunc

WithK sets the k parameter for the Sketch.

Jump to

Keyboard shortcuts

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