bloom

package module
v1.0.0-...-68fae00 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

Bloom Filters for Golang

Bloom filter for go, backed by redis or in process bitset

For more information on the uses of Bloom filters, please read https://en.wikipedia.org/wiki/Bloom_filter

Example Usage (in process):

install with go get gopkg.in/bculberson/bloom.v1

import "gopkg.in/bculberson/bloom.v1"

This bloom filter is initialized to hold 1000 keys and will have a false positive rate of 1% (.01).

b := bloom.New(1000, .01, bloom.NewBitSet())
b.Add([]byte("some key"))
exists, _ := b.Exists([]byte("some key"))
doesNotExist, _ := b.Exists([]byte("some other key"))

Example Usage (redis backed):

This bloom filter is initialized to hold 1000 keys and will have a false positive rate of 1% (.01).

This library uses http://github.com/garyburd/redigo/redis

pool := &redis.Pool{
    MaxIdle:     3,
    IdleTimeout: 240 * time.Second,
    Dial:        func() (redis.Conn, error) { return redis.Dial("tcp", addr) },
}


conn := pool.Get()
bitSet := bloom.NewRedisBitSet("test_key", conn)
b := bloom.New(1000, .01, bitSet)
b.Add([]byte("some key"))
exists, _ := b.Exists([]byte("some key"))
doesNotExist, _ := b.Exists([]byte("some other key"))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitSet

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

func NewBitSet

func NewBitSet() *BitSet

func (*BitSet) Set

func (b *BitSet) Set(offsets []uint) error

func (*BitSet) Test

func (b *BitSet) Test(offsets []uint) (bool, error)

type BitSetProvider

type BitSetProvider interface {
	Set([]uint) error
	Test([]uint) (bool, error)
}

type BloomFilter

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

func New

func New(n uint, fp float64, bitSet BitSetProvider) *BloomFilter

Creates a new Bloom filter for about n items with fp false positive rate

func (*BloomFilter) Add

func (f *BloomFilter) Add(data []byte) error

func (*BloomFilter) Exists

func (f *BloomFilter) Exists(data []byte) (bool, error)

type Connection

type Connection interface {
	Do(cmd string, args ...interface{}) (reply interface{}, err error)
	Flush() error
	Send(cmd string, args ...interface{}) error
}

type RedisBitSet

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

func NewRedisBitSet

func NewRedisBitSet(key string, conn Connection) *RedisBitSet

func (*RedisBitSet) Set

func (r *RedisBitSet) Set(offsets []uint) error

func (*RedisBitSet) Test

func (r *RedisBitSet) Test(offsets []uint) (bool, error)

Jump to

Keyboard shortcuts

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