hll

package
Version: v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package hll provides a hyperloglog structure for estimating the cardinality of multisets

Index

Constants

View Source
const (
	// Version is the version number of the binary serialization format. All
	// prior versions up to and including this one are deserializable by this
	// package.
	Version = 1
)

Variables

View Source
var ErrIncompatibleVersion = errors.New("hll: incompatible version")

Functions

func Len

func Len(p uint8) int

Len returns the length of the buffer required to serialize a counter with precision p which must be in the range [4,18]

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

func New

func New(p uint8) Counter

New creates a new hyperloglog counter with the specified precision. p must be in the range [4,18]

func WithBytes

func WithBytes(buf []byte) (Counter, error)

WithBytes creates a hyperloglog counter that uses buf as its backing storage, preserving any existing data in the byte slice. Any subsequent writes to the counter will mutate buf. The layout of the byte buffer must match the layout used by the WriteTo method.

func (*Counter) Add

func (c *Counter) Add(v []byte)

func (*Counter) Count

func (c *Counter) Count() int64

Count returns an estimate of the number of distinct items that have been added to the counter.

func (*Counter) HarmonicCount

func (c *Counter) HarmonicCount() int64

func (*Counter) Len

func (c *Counter) Len() int

Len returns the length of the buffer required to serialize the counter.

func (*Counter) LinearCount

func (c *Counter) LinearCount() int64

func (*Counter) PoissonCount

func (c *Counter) PoissonCount() int64

func (*Counter) ReadFrom

func (c *Counter) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads a binary representation of the counter from r overwriting any previous configuration. It adheres to the io.ReaderFrom interface protocol. It reads data from r until EOF or error. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned.

func (*Counter) Reset

func (c *Counter) Reset()

Reset reverts the counter to a zero count without reallocating the backing buffer.

func (*Counter) WriteTo

func (c *Counter) WriteTo(w io.Writer) (int64, error)

WriteTo writes a binary representation of the counter to w. It adheres to the io.WriterTo interface protocol. The return value is the number of bytes written. Any error encountered during the write is also returned.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL