Documentation
¶
Overview ¶
Package bloom provides a Bloom filter implementation for probabilistic existence checks. Bloom filters are space-efficient but do not support deletion. Use periodic rebuilds when the underlying dataset changes.
Example:
storage := memory.New(memory.WithExpectedItems(100000)) filter := bloom.New(storage) filter.Add(ctx, "user:123") exists, _ := filter.MightExist(ctx, "user:123") // true
Index ¶
- type Filter
- func (f *Filter) Add(ctx context.Context, value string) error
- func (f *Filter) AddBatch(ctx context.Context, values iter.Seq[string]) error
- func (f *Filter) Close(ctx context.Context) error
- func (f *Filter) LastRebuild() time.Time
- func (f *Filter) MightExist(ctx context.Context, value string) (bool, error)
- func (f *Filter) Rebuild(ctx context.Context, loader probfilter.DataLoader) error
- func (f *Filter) Stats(ctx context.Context) (*probfilter.FilterStats, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is a Bloom filter facade that wraps a storage backend. It implements probfilter.RebuildableFilter.
func New ¶
New creates a new Bloom filter with the specified storage backend.
Example:
storage := memory.New(memory.WithExpectedItems(100000)) filter := bloom.New(storage)
func (*Filter) LastRebuild ¶
LastRebuild returns the time of the last successful rebuild.
func (*Filter) MightExist ¶
MightExist checks if a value might exist in the filter.
func (*Filter) Rebuild ¶
func (f *Filter) Rebuild(ctx context.Context, loader probfilter.DataLoader) error
Rebuild recreates the filter from scratch using the provided data loader.
func (*Filter) Stats ¶
func (f *Filter) Stats(ctx context.Context) (*probfilter.FilterStats, error)
Stats returns current filter statistics.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package storages defines the storage interface for Bloom filter backends.
|
Package storages defines the storage interface for Bloom filter backends. |
|
memory
Package memory provides an in-memory Bloom filter storage implementation using the bits-and-blooms/bloom library.
|
Package memory provides an in-memory Bloom filter storage implementation using the bits-and-blooms/bloom library. |
|
redis
Package redis provides a Redis-backed Bloom filter storage implementation using RedisBloom module BF.* commands.
|
Package redis provides a Redis-backed Bloom filter storage implementation using RedisBloom module BF.* commands. |