bcount

package module
v0.0.0-...-dff21be Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2014 License: MIT Imports: 1 Imported by: 0

README

bcount

Cardinality counter that uses bloom filter internally.

GoDoc Build Status

Documentation

Overview

Package bcount implements a counter for counting distinct values.

As an alternative to approach, you can use HyperLogLog algorithm:

https://github.com/avisagie/gohll
https://github.com/eclesh/hyperloglog
https://github.com/dustin/go-probably

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BCount

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

BCount is a distict value counter that uses a bloom filter internally. It uses constant space in memory regardless of number of items counted. Mehtods of this struct are not goroutine-safe.

Example
// Create a new counter for 100 items with 1% false positive rate
counter := New(100, 0.01)

// Count some values
counter.Add([]byte("foo"))
counter.Add([]byte("bar"))
counter.Add([]byte("baz"))
counter.Add([]byte("baz")) // Same item (won't increment the counter)

// Get the counter value
fmt.Println(counter.Count())
Output:

3

func New

func New(n uint, fp float64) *BCount

New creates a new counter for about n items with fp false positive rate.

func (*BCount) Add

func (c *BCount) Add(data []byte)

Add item to counter. The count will only be incremented if the data is not added before.

func (*BCount) Cap

func (c *BCount) Cap() uint

Cap returns the capacity of the internal bloom filter.

func (*BCount) Count

func (c *BCount) Count() uint64

Count returns the number of distinct items added to counter via Add().

func (*BCount) Reset

func (c *BCount) Reset()

Reset clears all the data in a Bloom filter and resets the count to zero.

Jump to

Keyboard shortcuts

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