Skip to main content

OppoBloomFilter

This class implements the OppoBloomFilter, as proposed in the linked GitHub repository and blog post. It provides functionality related to this specific type of filter, likely for membership testing or similar data structure operations.

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. This method marks the presence of an ID, ensuring that subsequent 'Contains' calls for the same ID will return true.

Parameters

NameTypeDescription
_context.ContextThe context for the operation, allowing for cancellation and timeouts.
id[]byteThe byte slice representing the unique identifier to be added 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 determines if an ID has been previously added to the filter.

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).