Skip to content

Go implementation of Hyper Log Log

License

Notifications You must be signed in to change notification settings

mtchavez/go-hll

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-hll

Latest Version Test Go Documentation Go Report Card Maintainability Test Coverage

Go implementation of Hyper Log Log

Install

go get github.com/mtchavez/go-hll/hll

Usage

Create new

New hyper log log table with a desired error

package main

import (
  "github.com/mtchavez/go-hll/hll"
)

func main() {
  hll := NewWithErr(0.065)
}

New with default error

package main

import (
  "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

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)
  }
}

Count

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)

Documentation

Docs can be generated locally using godoc or go to godoc.org

Benchmarks

# 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

Tests

Run tests using go test.

License

Written by Chavez

Released under the MIT License: http://www.opensource.org/licenses/mit-license.php