Esempio n. 1
0
func (s *Store) TodayUniqueCount(siteId int64) (cnt int64, e error) {
	var (
		hl *hyperloglog.HyperLogLogPlus
	)
	hl, e = s.getHyperLoglog(siteId)
	if e != nil {
		return
	}
	cnt = int64(hl.Count())
	return
}
Esempio n. 2
0
func (s *Store) TodayUnique(siteId int64, uid int64) (cnt int64, e error) {
	var (
		hl *hyperloglog.HyperLogLogPlus
	)
	hl, e = s.getHyperLoglog(siteId)
	if e != nil {
		return
	}

	h := fnv.New64a()
	b := make([]byte, 4)
	binary.BigEndian.PutUint32(b, uint32(uid))
	io.WriteString(h, hex.EncodeToString(b))
	hl.Add(h)

	// encode and store hyperloglog
	var bts []byte
	bts, e = hl.GobEncode()
	if e != nil {
		return
	}
	e = s.ldb.Put(itob32(siteId), bts, nil)
	if e != nil {
		return
	}

	cnt = int64(hl.Count())

	return
}