Skip to main content

OppoBloomFilter

This class implements the OppoBloomFilter, as proposed in the linked GitHub repository and blog post. It provides functionality for a data structure that is the opposite of a traditional Bloom filter.

Methods​


getIndex()​

@classmethod
def getIndex(
id: []byte
) - > int32

Calculates the index for a given ID within the filter's internal array. This method is used internally to determine where an ID would be stored or checked.

Parameters​

NameTypeDescription
id[]byteThe byte slice representing the unique identifier for which to calculate the index.

Returns​

TypeDescription
int32The calculated index as an integer.

Add()​

@classmethod
def Add(
_: context.Context,
id: []byte
) - > bool

Adds an ID to the OppoBloomFilter, marking its presence. This method is used to populate the filter with known IDs.

Parameters​

NameTypeDescription
_context.ContextThe context for the operation, allowing for cancellation and timeouts.
id[]byteThe byte slice representing the unique identifier to add to the filter.

Returns​

TypeDescription
boolA boolean indicating whether the ID was successfully added (true) or if it was already present (false).

Contains()​

@classmethod
def Contains(
_: context.Context,
id: []byte
) - > bool

Checks if an ID is present in the OppoBloomFilter. This method is used to query the filter for the existence of an ID.

Parameters​

NameTypeDescription
_context.ContextThe context for the operation, allowing for cancellation and timeouts.
id[]byteThe byte slice representing the unique identifier to check for existence in the filter.

Returns​

TypeDescription
boolA boolean indicating whether the ID is present in the filter (true) or not (false).