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
| Name | Type | Description |
|---|---|---|
| id | []byte | The byte slice representing the unique identifier for which to calculate the index. |
Returns
| Type | Description |
|---|---|
int32 | The 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
| Name | Type | Description |
|---|---|---|
| _ | context.Context | The context for the operation, allowing for cancellation and timeouts. |
| id | []byte | The byte slice representing the unique identifier to add to the filter. |
Returns
| Type | Description |
|---|---|
bool | A 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
| Name | Type | Description |
|---|---|---|
| _ | context.Context | The context for the operation, allowing for cancellation and timeouts. |
| id | []byte | The byte slice representing the unique identifier to check for existence in the filter. |
Returns
| Type | Description |
|---|---|
bool | A boolean indicating whether the ID is present in the filter (true) or not (false). |