Files
David Reiss 53f127cc40 Matching fairness: count-min sketch for counting (#8033)
## What changed?
Add new Counter implementations:
- count-min sketch for high cardinality of keys
- hybrid to switch from map to sketch when number of keys gets high
enough

## Why?
Support high cardinality of fairness keys.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2025-07-22 16:43:59 +01:00

24 lines
480 B
Go

package counter
// mapCounter is a Counter that stores counts in a map.
// mapCounter is not safe for concurrent use.
type mapCounter struct {
m map[string]int64
}
var _ Counter = (*mapCounter)(nil)
func NewMapCounter() *mapCounter {
return &mapCounter{m: make(map[string]int64)}
}
func (m *mapCounter) GetPass(key string, base, inc int64) int64 {
c := max(base, m.m[key]+inc)
m.m[key] = c
return c
}
func (m *mapCounter) EstimateDistinctKeys() int {
return len(m.m)
}