# README
go-bloomfilter
go-bloomfilter is implemented by Golang which supports in-memory and Redis. Moreover, it’s available for a duration-based rotation.
Resources
Features
- Supporting bitmap: in-memory and Redis
- Rotation
Installation
go get github.com/x0rworld/go-bloomfilter
Quickstart
package main
import (
"context"
"github.com/bits-and-blooms/bloom/v3"
"github.com/x0rworld/go-bloomfilter/config"
"github.com/x0rworld/go-bloomfilter/factory"
"log"
)
func main() {
m, k := bloom.EstimateParameters(100, 0.01)
// configure factory config
cfg := config.NewDefaultFactoryConfig()
// modify config
cfg.FilterConfig.M = uint64(m)
cfg.FilterConfig.K = uint64(k)
// create factory by config
ff, err := factory.NewFilterFactory(cfg)
if err != nil {
log.Println(err)
return
}
// create filter by factory
f, err := ff.NewFilter(context.Background())
if err != nil {
log.Println(err)
return
}
// manipulate filter: Exist & Add
data := "hello world"
exist, err := f.Exist(data)
if err != nil {
log.Println(err)
return
}
// data: hello world, exist: false
log.Printf("data: %v, exist: %v\n", data, exist)
err = f.Add(data)
if err != nil {
log.Println(err)
return
}
// add data: hello world
log.Printf("add data: %s\n", data)
exist, err = f.Exist(data)
if err != nil {
log.Println(err)
return
}
// data: hello world, exist: true
log.Printf("data: %v, exist: %v\n", data, exist)
}
More examples such as rotation could be found in Examples.
# Packages
Package bitmap provides ways for filter to manipulate bit set.
Package config is used to generate filter by factory.
No description provided by the author
No description provided by the author
Package factory is used to generate instances such as filter, bitmap.
Package filter manipulates bitmap to check and add the element.
Package mock is a generated GoMock package.