Documentation ¶
Overview ¶
Package bcount implements a counter for counting distinct values.
As an alternative to approach, you can use HyperLogLog algorithm:
https://github.com/avisagie/gohll https://github.com/eclesh/hyperloglog https://github.com/dustin/go-probably
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BCount ¶
type BCount struct {
// contains filtered or unexported fields
}
BCount is a distict value counter that uses a bloom filter internally. It uses constant space in memory regardless of number of items counted. Mehtods of this struct are not goroutine-safe.
Example ¶
// Create a new counter for 100 items with 1% false positive rate counter := New(100, 0.01) // Count some values counter.Add([]byte("foo")) counter.Add([]byte("bar")) counter.Add([]byte("baz")) counter.Add([]byte("baz")) // Same item (won't increment the counter) // Get the counter value fmt.Println(counter.Count())
Output: 3
func (*BCount) Add ¶
Add item to counter. The count will only be incremented if the data is not added before.
Click to show internal directories.
Click to hide internal directories.