pool: support CountMany() using hyperloglog.

This commit is contained in:
fiatjaf
2024-11-16 16:59:24 -03:00
parent 99e45035d5
commit 0d40b40c9c
7 changed files with 72 additions and 19 deletions

View File

@@ -0,0 +1,30 @@
package hyperloglog
import (
"math"
)
const two32 = 1 << 32
func linearCounting(m uint32, v uint32) float64 {
fm := float64(m)
return fm * math.Log(fm/float64(v))
}
func clz56(x uint64) uint8 {
var c uint8
for m := uint64(1 << 55); m&x == 0 && m != 0; m >>= 1 {
c++
}
return c
}
func countZeros(s []uint8) uint32 {
var c uint32
for _, v := range s {
if v == 0 {
c++
}
}
return c
}