package ddsketch

import "github.com/DataDog/sketches-go/ddsketch"

Example

Code:play 

package main

import (
	"fmt"
	"math/rand"

	"github.com/DataDog/sketches-go/ddsketch"
)

func main() {
	rand.Seed(1234)

	c := ddsketch.NewDefaultConfig()
	sketch := ddsketch.NewDDSketch(c)

	for i := 0; i < 500; i++ {
		v := rand.NormFloat64()
		sketch.Add(v)
	}

	anotherSketch := ddsketch.NewDDSketch(c)
	for i := 0; i < 500; i++ {
		v := rand.NormFloat64()
		anotherSketch.Add(v)
	}
	sketch.Merge(anotherSketch)

	fmt.Println(quantiles(sketch))
	fmt.Println(quantiles(anotherSketch))
}

func quantiles(sketch *ddsketch.DDSketch) []float64 {
	qs := []float64{0.5, 0.75, 0.9, 1}
	quantiles := make([]float64, len(qs))
	for i, q := range qs {
		quantiles[i] = sketch.Quantile(q)
	}
	return quantiles
}

Output:

[-0.06834362559246944 0.6404974768745979 1.2809242125081708 3.0655851632106974]
[0.03220264075781927 0.7071609687152794 1.4142438333843486 3.0655851632106974]

Index

Examples

Types

type Config

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

Config contains an offset for the bin keys which ensures that keys for positive numbers that are larger than minValue are greater than or equal to 1 while the keys for negative numbers are less than or equal to -1.

func NewConfig

func NewConfig(alpha float64, maxNumBins int, minValue float64) *Config

func NewDefaultConfig

func NewDefaultConfig() *Config

func (*Config) Key

func (c *Config) Key(v float64) int

func (*Config) Size

func (c *Config) Size() int

type DDSketch

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

DDSketch is an implementation of DDSketch.

func NewDDSketch

func NewDDSketch(c *Config) *DDSketch

NewDDSketch allocates a new DDSketch summary with relative accuracy alpha.

func (*DDSketch) Add

func (s *DDSketch) Add(v float64)

Add a new value to the summary.

func (*DDSketch) Avg

func (s *DDSketch) Avg() float64

func (*DDSketch) Count

func (s *DDSketch) Count() int64

func (*DDSketch) MakeCopy

func (s *DDSketch) MakeCopy() *DDSketch

func (*DDSketch) MemorySize

func (s *DDSketch) MemorySize() int

func (*DDSketch) Merge

func (s *DDSketch) Merge(o *DDSketch)

Merge another sketch (with the same maxNumBins and gamma) in place.

func (*DDSketch) Quantile

func (s *DDSketch) Quantile(q float64) float64

Quantile returns the estimate of the element at q.

func (*DDSketch) String

func (s *DDSketch) String() string

func (*DDSketch) Sum

func (s *DDSketch) Sum() float64

type Store

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

Store is a dynamically growing contiguous (non-sparse) implementation of the buckets of DogSketch

func NewStore

func NewStore(maxNumBins int) *Store

func (*Store) Add

func (s *Store) Add(key int)

func (*Store) Copy

func (s *Store) Copy(o *Store)

func (*Store) KeyAtRank

func (s *Store) KeyAtRank(rank int) int

Return the key for the value at rank

func (*Store) Length

func (s *Store) Length() int

func (*Store) MakeCopy

func (s *Store) MakeCopy() *Store

func (*Store) Merge

func (s *Store) Merge(o *Store)

func (*Store) Size

func (s *Store) Size() int

func (*Store) String

func (s *Store) String() string

Source Files

config.go ddsketch.go store.go

Version
v0.0.1
Published
Sep 23, 2019
Platform
windows/amd64
Imports
4 packages
Last checked
8 hours ago

Tools for package owners.