bloom

package
v0.1.27 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter interface {
	// Add inserts multiple elements into the Bloom filter.
	// Parameters:
	// - ctx: Context to control the execution and allow cancellation.
	// - elements: Variadic parameter for the elements to add to the Bloom filter.
	// Returns:
	// - error: An error if the addition fails, otherwise nil.
	Add(ctx context.Context, elements ...interface{}) error

	// Check verifies whether a single element is present in the Bloom filter.
	// Parameters:
	// - ctx: Context to control the execution and allow cancellation.
	// - element: The element to check in the Bloom filter.
	// Returns:
	// - bool: true if the element may be present, false otherwise.
	// - error: An error if the check operation fails, otherwise nil.
	Check(ctx context.Context, element interface{}) (bool, error)

	// CheckBatch verifies the presence of multiple elements in the Bloom filter.
	// Parameters:
	// - ctx: Context to control the execution and allow cancellation.
	// - elements: Variadic parameter for the elements to check in the Bloom filter.
	// Returns:
	// - []bool: Slice of boolean values indicating the presence of each element.
	// - error: An error if the check operation fails, otherwise nil.
	CheckBatch(ctx context.Context, elements ...interface{}) ([]bool, error)

	// Remove deletes a single element from the Bloom filter.
	// Parameters:
	// - ctx: Context to control the execution and allow cancellation.
	// - element: The element to remove from the Bloom filter.
	// Returns:
	// - error: An error if the removal fails, otherwise nil.
	Remove(ctx context.Context, element interface{}) error

	// RemoveBatch deletes multiple elements from the Bloom filter.
	// Parameters:
	// - ctx: Context to control the execution and allow cancellation.
	// - elements: Variadic parameter for the elements to remove from the Bloom filter.
	// Returns:
	// - error: An error if the removal fails, otherwise nil.
	RemoveBatch(ctx context.Context, elements ...interface{}) error
}

Filter is an interface that defines methods for interacting with a Bloom filter.

func InitRedisBloomFilter

func InitRedisBloomFilter(client redis.Cmdable, opts ...Option) Filter

InitRedisBloomFilter initializes a new Bloom filter with given Redis client and optional settings.

type Option

type Option func(*Options)

Option is a function type that takes an Options pointer and configures it.

func WithRedisKey

func WithRedisKey(key string) Option

WithRedisKey returns an Option that sets the RedisKey in Options. Parameters: - key: The Redis key to be set in Options. Returns: - Option: A function that sets the RedisKey in Options.

type Options

type Options struct {
	RedisKey string // RedisKey is the key under which the Bloom filter data is stored in Redis.
}

Options holds configuration settings for the RedisBloomFilter.

type RedisBloomFilter

type RedisBloomFilter struct {
	// contains filtered or unexported fields
}

RedisBloomFilter represents a Bloom filter backed by Redis.

func (*RedisBloomFilter) Add

func (bf *RedisBloomFilter) Add(ctx context.Context, elements ...interface{}) error

Add inserts multiple elements into the Bloom filter. Parameters: - ctx: Context to control execution. - elements: Variadic parameter for the elements to add.

func (*RedisBloomFilter) Check

func (bf *RedisBloomFilter) Check(ctx context.Context, element interface{}) (bool, error)

Check checks if a single element exists in the Bloom filter. Parameters: - ctx: Context to control execution. - element: The element to check. Returns: - bool: true if the element exists, false otherwise. - error: any error encountered during the operation.

func (*RedisBloomFilter) CheckBatch

func (bf *RedisBloomFilter) CheckBatch(ctx context.Context, elements ...interface{}) ([]bool, error)

CheckBatch checks if multiple elements exist in the Bloom filter. Parameters: - ctx: Context to control execution. - elements: Variadic parameter for the elements to check. Returns: - []bool: Slice of boolean values indicating existence of each element. - error: any error encountered during the operation.

func (*RedisBloomFilter) Remove

func (bf *RedisBloomFilter) Remove(ctx context.Context, element interface{}) error

Remove removes a single element from the Bloom filter. This is a convenience method that calls RemoveBatch internally. Parameters: - ctx: Context to control execution. - element: The element to remove.

func (*RedisBloomFilter) RemoveBatch

func (bf *RedisBloomFilter) RemoveBatch(ctx context.Context, elements ...interface{}) error

RemoveBatch removes multiple elements from the Bloom filter. Parameters: - ctx: Context to control execution. - elements: Variadic parameter for the elements to remove. Returns: - error: any error encountered during the operation.

Jump to

Keyboard shortcuts

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