bloomfilter

package module
v0.0.0-...-6c4e374 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 5 Imported by: 0

README

go-bloomfilter

A simple and high-performance Bloom filter written in golang.

Support memory storage and redis.

Examples

MemoryBloomFilter
import bloomfilter "github.com/alovn/go-bloomfilter"

bloom := bloomfilter.NewMemoryBloomFilter(10000)
_ = bloom.Put([]byte("bloom"))
exists,err := bloom.MightContain(bs)

RedisBloomFilter
import bloomfilter "github.com/alovn/go-bloomfilter"

cli := redis.NewClient(&redis.Options{
    Addr:     "127.0.0.1:6379",
    Password: "",
    DB:       0,
})

key := "redis bloomfilter"

bloom := bloomfilter.NewRedisBloomFilter(cli, "test", 10000)

bs := []byte(key)
_ = bloom.Put(bs)
exists, err := bloom.MightContain(bs)

Documentation

Overview

A simple and high-performance Bloom filter written in golang.

import bloomfilter "github.com/splashing-atom/go-bloomfilter"

MemoryBloomFilter:

bloom := bloomfilter.NewMemoryBloomFilter(10000)
bs := []byte("bloom")
_ = bloom.Put(bs)
exists, err := bloom.MightContain(bs)

RedisBloomFilter:

cli := redis.NewClient(&redis.Options{
	Addr:     "127.0.0.1:6379",
	Password: "",
	DB:       0,
})
key := "redis bloomfilter"
bloom := bloomfilter.NewRedisBloomFilter(cli, "test", 10000)
bs := []byte(key)
_ = bloom.Put(bs)
exists, err := bloom.MightContain(bs)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilter

type BloomFilter interface {
	Put([]byte) error
	MightContain([]byte) (bool, error)
}

BloomFilter interface define

func NewMemoryBloomFilter

func NewMemoryBloomFilter(size uint64) BloomFilter

NewMemoryBloomFilter implementation with memory

type RedisBackedBloomFilter

type RedisBackedBloomFilter interface {
	BloomFilter
	PutCtx(context.Context, []byte) error
	MightContainCtx(context.Context, []byte) (bool, error)
	BucketCount() uint64
	BucketName(index uint64) string
}

func NewRedisBloomFilter

func NewRedisBloomFilter(redisCli *redis.Client, redisKey string, size uint64) RedisBackedBloomFilter

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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