Discover Packages
github.com/betamos/distinct
package
module
Version:
v0.0.0-...-6c5968f
Opens a new window with list of versions in this module.
Published: May 17, 2024
License: MIT
Opens a new window with license information.
Imports: 2
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Distinct
This micro-library estimates the number of distinct elements in a stream:
import (
"fmt"
"github.com/betamos/distinct"
)
// Uses a map of size 200
c := distinct.NewCounter[int](200, nil)
for i := 0; i < 100000; i++ {
c.Add(i % 300)
}
fmt.Println(c.Estimate()) // Should be somewhere around 300
It's based on Distinct Elements in Streams: An Algorithm for the (Text) Book .
Expand ▾
Collapse ▴
Documentation
¶
Returns a suitable threshold value given (see Chernoff Bounds):
epsilon: relative error of the estimate, lower is more accurate
delta: confidence level, lower is more accurate
m: total expected elements in the stream
Counter of distinct elements, using https://arxiv.org/pdf/2301.10191
Create a new counter with O(threshold) memory complexity.
If src is nil, a source with a random seed will be used.
Add an element to the counter
Returns the current estimate
Source Files
¶
Click to show internal directories.
Click to hide internal directories.