BBloomFjord
Workflows

Coding workflows · Probabilistic Bloom membership

03
Built around your work

A concrete starting point

Store byte keys of at most 1024 bytes in a Bloom filter with one to 8192 bits. Check duplicate insertion and inserted keys, demonstrating that a positive result can be a false positive rather than proof of membership.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Probabilistic Bloom membership

A concrete starting point
from hashlib import sha256

class Bloom:
    def __init__(self, width):
        if type(width) is not int or not 1 <= width <= 8192:
            raise ValueError("width.range")
        self.width, self.bits = width, 0
    def positions(self, key):
        if not isinstance(key, bytes) or len(key) > 1024:
            raise ValueError("key.bytes")
        digest = sha256(key).digest()
        return [int.from_bytes(digest[i:i+4], "big") % self.width
                for i in (0, 4, 8, 12)]
    def add(self, key):
        for position in self.positions(key):
            self.bits |= 1 << position
    def maybe_contains(self, key):
        return all(self.bits & (1 << p) for p in self.positions(key))

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗