cuckoo

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: 5 Imported by: 0

README

cuckoo

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

Package cuckoo provides a Cuckoo filter implementation for probabilistic existence checks. Unlike Bloom filters, Cuckoo filters support deletion of individual items at the cost of slightly higher memory overhead.

Documentation

Overview

Package cuckoo provides a Cuckoo filter implementation for probabilistic existence checks. Unlike Bloom filters, Cuckoo filters support deletion of individual items.

Example:

storage := memory.New(memory.WithCapacity(100000))
filter := cuckoo.New(storage)
filter.Add(ctx, "user:123")
exists, _ := filter.MightExist(ctx, "user:123") // true
filter.Delete(ctx, "user:123")
exists, _ = filter.MightExist(ctx, "user:123") // false

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 Cuckoo filter facade that wraps a storage backend. It implements probfilter.DeletableFilter.

func New

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

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

Example:

storage := memory.New(memory.WithCapacity(100000))
filter := cuckoo.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) Delete

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

Delete removes a value from the filter.

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) 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 Cuckoo filter backends.
Package storages defines the storage interface for Cuckoo filter backends.
memory
Package memory provides an in-memory Cuckoo filter storage implementation using the seiflotfy/cuckoofilter library.
Package memory provides an in-memory Cuckoo filter storage implementation using the seiflotfy/cuckoofilter library.
redis
Package redis provides a Redis-backed Cuckoo filter storage implementation using RedisBloom module CF.* commands.
Package redis provides a Redis-backed Cuckoo filter storage implementation using RedisBloom module CF.* commands.

Jump to

Keyboard shortcuts

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