Documentation ¶
Index ¶
Constants ¶
const ( // DefaultHashes represents the default value for the number of hashes. DefaultHashes = 4 // DefaultSlots represents the default value for the number of slots. DefaultSlots = 8192 )
const ( // DefaultRateHashes represents the default value for the number of hashes. DefaultRateHashes = 4 // DefaultRateSlots represents the default value for the number of slots. DefaultRateSlots = 1024 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Estimator ¶
type Estimator[K Key] struct { // contains filtered or unexported fields }
Estimator is an implementation of the count-min sketch data structure.
An Estimator instance is lock-free, but is safe to use concurrency from multiple goroutines.
For more info: https://en.wikipedia.org/wiki/Count%E2%80%93min_sketch
func NewEstimator ¶
NewEstimator returns a new Estimator instance using the default hash and slot sizes.
func NewEstimatorWithSize ¶
NewEstimatorWithSize returns a new Estimator instance using the provided number of hashes and slots. This function panics if hashes or slots are less than or equal to zero.
type Rate ¶
type Rate[K Key] struct { // contains filtered or unexported fields }
Rate is a probabilistic rate estimator over a given interval. Internally, it uses multiple `Estimator`s to track the number of events per key.
A Rate instance is lock-free, but is safe to use concurrency from multiple goroutines.
func NewRate ¶
NewRate returns a new Rate instance using the provided interval and default sizes. NewRate panics if interval is smaller than 1 millisecond.
func NewRateWithSize ¶
NewRateWithSize returns a new Rate instance using the provided interval and hash/slot sizes. NewRateWithSize panics if interval is smaller than 1 millisecond.