cbfilter

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

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

Go to latest
Published: Feb 26, 2014 License: Apache-2.0 Imports: 5 Imported by: 3 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cbfilter

Golang Counting Bloom Filter Implementation

A counting bloom filter implementation with arbitrary number (1-8) of bits per slot. Uses murmur3 and Kirsch and MitzenMacher method for determining k independent hash functions efficiently.

Usage is simple:

const (
      N = <number insertions>
      B = <bits-per-slot>
      FP = <max-false-positive-prob>
)

f, err := NewFilter(N, B, FP)
if err != nil {
   log.Error("error creating filter:", err)
   return
}

f.AddKey("a")
f.HasKey("a")
f.RemoveKey("a")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	K        uint32 // Number of hashes
	N        uint32 // Number of insertions
	R        uint32 // Number of putative removals
	B        uint32 // Number of bits in each slot
	M        uint32 // Number of slots in filter
	MaxCount uint32 // Maximum count for a slot
	Data     []byte // Slot data
	// contains filtered or unexported fields
}

filter is a counting bloom filter, used to approximate the number of differences between InfoStores from different nodes, with minimal network overhead.

func NewFilter

func NewFilter(N uint32, B uint32, maxFP float64) (*Filter, error)

NewFilter allocates and returns a new filter with expected number of insertions N, Number of bits per slot B, and expected value of a false positive < maxFP. Number of bits must be 0 < B <= 8.

func (*Filter) AddKey

func (f *Filter) AddKey(key string)

AddKey adds the key to the Filter.

func (*Filter) HasKey

func (f *Filter) HasKey(key string) bool

HasKey checks whether key has been added to the Filter. The chance this method returns an incorrect value is given by ProbFalsePositive().

func (*Filter) RemoveKey

func (f *Filter) RemoveKey(key string) bool

RemoveKey removes a key by first verifying it's likely been seen and then decrementing each of the slots it hashes to. Returns true if the key was "removed"; false otherwise.

Jump to

Keyboard shortcuts

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