bloomfilter — A NEO specific bloomfilter implementation

While ready to install 3rd party bloom filter implementations exist on PyPi, they unfortunately do not comply with the NEO implementation.

Bloomfilter’s can be broadcasted over the network and thus there is a need to have identical results.

class neo3.core.cryptography.bloomfilter.BloomFilter(m, k, ntweak, elements=None)

Bases: object

BloomFilter implementation conforming to NEO’s implementation. # noqa

Parameters
  • m (int) – size of bitarray.

  • k (int) – number of hash functions.

  • ntweak (int) – correction factor.

  • elements (Optional[bytes]) – hex-escaped bytearray of values to create the bitarray from. Warning: the bit array is truncated to size m.

add(element)

Add an element to the filter.

Parameters

element (bytes) – hex-escaped bytearray.

Return type

None

check(element)

Check if the element is present

Parameters

element (bytes) – hex-escaped bytearray

Returns: True if present. False if not present.

Return type

bool

get_bits()

Return the filter bits.

Return type

bytes