Go implementation of Hyper Log Log
go get github.com/mtchavez/go-hll/hll
New hyper log log table with a desired error
package main
import (
"github.com/mtchavez/go-hll/hll"
)
func main() {
hll := NewWithErr(0.065)
}
package main
import (
"github.com/mtchavez/go-hll/hll"
)
func main() {
// Uses DefaultErr of 0.065
hll := New()
hll.Add("foo")
}
Add some words to the table
package main
import (
"github.com/mtchavez/go-hll/hll"
)
func main() {
hll := NewWithErr(0.065)
words := []string{"apple", "this is bananas", "kiwi kiwi kiwi", "Peach is a peach", "apple banana peach wiki pear"}
for _, word := range words {
hll.Add(word)
}
}
Get the count and calculate the error of your hyper log log
hll := NewWithErr(0.065)
words := []string{"apple", "this is bananas", "kiwi kiwi kiwi", "Peach is a peach", "apple banana peach wiki pear"}
for _, word := range words {
hll.Add(word)
}
count := hll.Count()
err := float32((count - uint32(len(words))) / uint32(len(words)) / 100.0)
fmt.Printf("\nCount: %d\nError: %f%%\n\n", count, err)
Docs can be generated locally using godoc
or go to godoc.org
# Updated: 2022-07-01
goos: darwin
goarch: arm64
pkg: github.com/mtchavez/go-hll/hll
BenchmarkHllNew-8 103207 11357 ns/op
BenchmarkHllAdd-8 15996489 74.95 ns/op
BenchmarkHllCount-8 156948 7598 ns/op
Run tests using go test
.
Written by Chavez
Released under the MIT License: http://www.opensource.org/licenses/mit-license.php