Ejemplo n.º 1
0
func (s *Store) getHyperLoglog(siteId int64) (hl *hyperloglog.HyperLogLogPlus, e error) {
	var (
		bts   []byte
		isNew bool = true
		ok    bool
	)
	key := itob32(siteId)
	if ok, e = s.ldb.Has(key, nil); ok {
		isNew = false
		bts, e = s.ldb.Get(key, nil)
		if e != nil {
			if leveldb.ErrNotFound == e {
				isNew = true
			} else {
				return
			}
		}
	}

	hl, e = hyperloglog.NewPlus(HyperlogPrecision)
	if e != nil {
		return
	}

	if !isNew {
		e = hl.GobDecode(bts)
		if e != nil {
			return
		}
	}

	return hl, nil
}
Ejemplo n.º 2
0
// NewSet generates a new Set and returns it
func NewSet(name string, tags []string) *Set {
	// error is only returned if precision is outside the 4-18 range
	// TODO: this is the maximum precision, should it be configurable?
	hll, _ := hyperloglog.NewPlus(18)
	return &Set{
		name: name,
		tags: tags,
		hll:  hll,
	}
}
Ejemplo n.º 3
0
func (s *Set) Flush() {
	s.HLL.HyperLogLogPlus, _ = hll.NewPlus(configHLLPrecision)
	s.Count = 0
}