Documentation ¶
Overview ¶
Package hyperloglog implements the HyperLogLog algorithm for cardinality estimation. In English: it counts things. It counts things using very small amounts of memory compared to the number of objects it is counting.
For a full description of the algorithm, see the paper HyperLogLog: the analysis of a near-optimal cardinality estimation algorithm by Flajolet, et. al.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HyperLogLog ¶
type HyperLogLog struct {
// contains filtered or unexported fields
}
func New ¶
func New(registers uint) (*HyperLogLog, error)
Return a new HyperLogLog with the given number of registers. More registers leads to lower error in your estimated count, at the expense of memory.
Choose a power of two number of registers, depending on the amount of memory you're willing to use and the error you're willing to tolerate. Each register uses one byte of memory.
Approximate error will be:
1.04 / sqrt(registers)
func (*HyperLogLog) Add ¶
func (h *HyperLogLog) Add(val uint32)
Add to the count. val should be a 32 bit unsigned integer from a good hash function.
func (*HyperLogLog) Merge ¶
func (h1 *HyperLogLog) Merge(h2 *HyperLogLog) error
Merge another HyperLogLog into this one. The number of registers in each must be the same.
func (*HyperLogLog) Reset ¶
func (h *HyperLogLog) Reset()
Reset all internal variables and set the count to zero.