bloom

package
v0.0.0-...-af21e5c Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const BucketNumber = 1 << 8

BucketNumber is the number of cache buckets

Variables

This section is empty.

Functions

func EstimateCount

func EstimateCount(n uint, p float64, limitP float64) uint

func EstimateParameters

func EstimateParameters(n uint, p float64) (uint, uint)

func EstimateRate

func EstimateRate(m, k, count uint) (p float64)

func NewKeyCache

func NewKeyCache(cacheSize uint) *keyCache

NewKeyCache creates a new cache

Types

type BloomFilter

type BloomFilter struct {
	*sync.RWMutex
	// contains filtered or unexported fields
}

BloomFilter holds all the storage filters.

func NewBloomFilter

func NewBloomFilter(st StorageType, client *redis.Client, key string, n uint, p float64, cacheSize uint) (*BloomFilter, error)

NewBloomFilter creates and returns a new bloom filter using Redis as a backend. if you do not want to use cache, please set cacheSize to 0.

func (*BloomFilter) Append

func (b *BloomFilter) Append(value []byte) (err error)

Append is used to append a value to the queue.

func (*BloomFilter) Exists

func (b *BloomFilter) Exists(value []byte) (exists bool, err error)

Exists checks if the given value is in the bloom filter or not. False positives might occur.

func (*BloomFilter) ExistsAndAppend

func (b *BloomFilter) ExistsAndAppend(value []byte) (exists bool, err error)

ExistsAndAppend check and append

func (*BloomFilter) Reset

func (b *BloomFilter) Reset(n uint, p float64) (err error)

Reset TODO

type RedisStorage

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

RedisStorage is a struct representing the Redis backend for the bloom filter.

func NewRedisStorage

func NewRedisStorage(client *redis.Client, bf *BloomFilter, key string, hashIter uint, size uint) (*RedisStorage, error)

NewRedisStorage creates a Redis backend storage to be used with the bloom filter.

func (*RedisStorage) Append

func (s *RedisStorage) Append(value []byte) error

Append appends the bit, which is to be saved, to the Redis.

func (*RedisStorage) Exists

func (s *RedisStorage) Exists(value []byte) (ret bool, err error)

Exists checks if the given bit exists in the Redis backend.

func (*RedisStorage) ExistsAndAppend

func (s *RedisStorage) ExistsAndAppend(value []byte) (ret bool, err error)

ExistsAndAppend checks and append

func (*RedisStorage) Init

func (s *RedisStorage) Init(hashIter, size uint) (err error)

Init takes care of settings every bit to 0 in the Redis bitset.

type StorageType

type StorageType int

StorageType is storage types

const (
	// Redis type
	Redis StorageType = iota
)

type UnavailableBloomType

type UnavailableBloomType string

UnavailableBloomType bloom error

func (UnavailableBloomType) Error

func (e UnavailableBloomType) Error() string

Jump to

Keyboard shortcuts

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