bloom

package
v0.0.0-...-c7901e9 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: MIT Imports: 7 Imported by: 0

README

bloom

import "github.com/altessa-s/go-atlas/data/probfilter/bloom"

Package bloom provides a Bloom filter implementation for probabilistic existence checks. Bloom filters are space-efficient but do not support deletion. Use periodic rebuilds via RebuildableFilter when the underlying dataset changes.

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

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

func New(storage storages.Storage, opt ...Option) *Filter

New creates a new Bloom filter with the specified storage backend.

Example:

storage := memory.New(memory.WithExpectedItems(100000))
filter := bloom.New(storage)

func (*Filter) Add

func (f *Filter) Add(ctx context.Context, value string) error

Add inserts a value into the filter.

func (*Filter) AddBatch

func (f *Filter) AddBatch(ctx context.Context, values iter.Seq[string]) error

AddBatch inserts multiple values into the filter.

func (*Filter) Close

func (f *Filter) Close(ctx context.Context) error

Close releases resources associated with the filter.

func (*Filter) LastRebuild

func (f *Filter) LastRebuild() time.Time

LastRebuild returns the time of the last successful rebuild.

func (*Filter) MightExist

func (f *Filter) MightExist(ctx context.Context, value string) (bool, error)

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.

type Option

type Option func(o *options)

Option is a functional option for configuring options.

func WithLogger

func WithLogger(v *slog.Logger) Option

WithLogger sets the logger option.

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.

Jump to

Keyboard shortcuts

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