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 ¶
- type Config
- func NewConfig(alpha float64, maxNumBins int, minValue float64) *Config
- func NewDefaultConfig() *Config
- func (c *Config) Key(v float64) int
- func (c *Config) Size() int
- type DDSketch
- func NewDDSketch(c *Config) *DDSketch
- func (s *DDSketch) Add(v float64)
- func (s *DDSketch) Avg() float64
- func (s *DDSketch) Count() int64
- func (s *DDSketch) MakeCopy() *DDSketch
- func (s *DDSketch) MemorySize() int
- func (s *DDSketch) Merge(o *DDSketch)
- func (s *DDSketch) Quantile(q float64) float64
- func (s *DDSketch) String() string
- func (s *DDSketch) Sum() float64
- type Store
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 NewDefaultConfig ¶
func NewDefaultConfig() *Config
func (*Config) Key ¶
func (*Config) Size ¶
type DDSketch ¶
type DDSketch struct {
// contains filtered or unexported fields
}
DDSketch is an implementation of DDSketch.
func NewDDSketch ¶
NewDDSketch allocates a new DDSketch summary with relative accuracy alpha.
func (*DDSketch) Add ¶
Add a new value to the summary.
func (*DDSketch) Avg ¶
func (*DDSketch) Count ¶
func (*DDSketch) MakeCopy ¶
func (*DDSketch) MemorySize ¶
func (*DDSketch) Merge ¶
Merge another sketch (with the same maxNumBins and gamma) in place.
func (*DDSketch) Quantile ¶
Quantile returns the estimate of the element at q.
func (*DDSketch) String ¶
func (*DDSketch) Sum ¶
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 (*Store) Add ¶
func (*Store) Copy ¶
func (*Store) KeyAtRank ¶
Return the key for the value at rank
func (*Store) Length ¶
func (*Store) MakeCopy ¶
func (*Store) Merge ¶
func (*Store) Size ¶
func (*Store) 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.