web3swift icon indicating copy to clipboard operation
web3swift copied to clipboard

Bloom filter improvement

Open JeneaVranceanu opened this issue 2 years ago • 1 comments

Here you can find an implementation of a bloom filter that could be used to implement a better version of bloom9. Looks like this link is unsecured due to issues with SSL certificate so I copied the code snippet.

This is not certain but looks like we can try to follow this example and potentially improve performance of bloom filter calculation:

# external imports
import sha3

class LogBloom:

    def __init__(self):
        self.content = bytearray(256)


   def add(self, element):
       if not isinstance(element, bytes):
           raise ValueError('element must be bytes')
        h = sha3.keccak_256()
        h.update(element)
        z = h.digest()

        for j in range(3):
            c = j * 2
            v = int.from_bytes(z[c:c+2], byteorder='big')
            v &= 0x07ff
            m = 255 - int(v / 8)
            n = v % 8
            self.content[m] |= (1 << n)

JeneaVranceanu avatar Aug 11 '22 14:08 JeneaVranceanu

@Kristenlike1234 This improvement is not implemented/tried out yet. The PR that was merged is mostly clean up, DocC update and slight performance improvement over the previous implementation.

JeneaVranceanu avatar Oct 04 '22 08:10 JeneaVranceanu