https://github.com/mtchavez/go-hll
Go implementation of Hyper Log Log
https://github.com/mtchavez/go-hll
go golang hyperloglog sketching-algorithm
Last synced: about 1 month ago
JSON representation
Go implementation of Hyper Log Log
- Host: GitHub
- URL: https://github.com/mtchavez/go-hll
- Owner: mtchavez
- License: mit
- Created: 2013-04-28T21:38:16.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2022-07-01T22:00:43.000Z (almost 3 years ago)
- Last Synced: 2025-03-26T12:46:53.241Z (2 months ago)
- Topics: go, golang, hyperloglog, sketching-algorithm
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-hll
[](https://github.com/mtchavez/go-hll/releases)
[](https://github.com/mtchavez/go-hll/actions/workflows/test.yml)
[](http://godoc.org/github.com/mtchavez/go-hll)
[](https://goreportcard.com/report/github.com/mtchavez/go-hll)
[](https://codeclimate.com/github/mtchavez/go-hll/maintainability)
[](https://codecov.io/gh/mtchavez/go-hll)Go implementation of Hyper Log Log
## Install
```go
go get github.com/mtchavez/go-hll/hll
```## Usage
- [New](#create-new)
- [New With Default Error](#new-with-default-error)
- [Adding](#adding)
- [Count](#count)### Create new
New hyper log log table with a desired error
```go
package mainimport (
"github.com/mtchavez/go-hll/hll"
)func main() {
hll := NewWithErr(0.065)
}
```### New with default error
```go
package mainimport (
"github.com/mtchavez/go-hll/hll"
)func main() {
// Uses DefaultErr of 0.065
hll := New()
hll.Add("foo")
}
```### Adding
Add some words to the table
```go
package mainimport (
"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)
}
}
```### Count
Get the count and calculate the error of your hyper log log
```go
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)```
## Documentation
Docs can be generated locally using ```godoc``` or go to [godoc.org](http://godoc.org/github.com/mtchavez/go-hll/hll)
## Benchmarks
```txt
# Updated: 2022-07-01goos: darwin
goarch: arm64
pkg: github.com/mtchavez/go-hll/hllBenchmarkHllNew-8 103207 11357 ns/op
BenchmarkHllAdd-8 15996489 74.95 ns/op
BenchmarkHllCount-8 156948 7598 ns/op
```## Tests
Run tests using ```go test```.
## License
Written by Chavez
Released under the MIT License: