Python Bloom Filter CLI
Python Bloom Filter — a runnable python project with source, install and run commands, and expected output.
Project
py-bloom-filter-cli
Entry point: bloom.py
Install
python bloom.pyRun
python bloom.pyTest
pytest bloom_test.pyExpected output
Bit-array bloom filter with k hash functions; adds items and tests membership.Dependencies
- python >=3.10
Verification evidence
Source reviewed against python standard library APIs. Commands verified for syntax; execution not yet exercised in CI.
Security note
Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.
What it does
Python Bloom Filter CLI is a self-contained python command-line program. Bit-array bloom filter with k hash functions; adds items and tests membership.
Install and run
python bloom.py
python bloom.py
Project structure
py-bloom-filter-cli/
├── bloom.py
└── README snippet above
Key source
# bloom.py
import hashlib
class Bloom:
def __init__(self, m, k): self.m, self.k, self.bits = m, k, 0
def _h(self, x, i): return int(hashlib.sha256(f"{i}:{x}".encode()).hexdigest(), 16) % self.m
def add(self, x):
for i in range(self.k): self.bits |= 1 << self._h(x, i)
def has(self, x):
return all(self.bits & (1 << self._h(x, i)) for i in range(self.k))
b = Bloom(1000, 4)
for w in ["a","b","c"]: b.add(w)
print([b.has(w) for w in ["a","d"]])
Testing
pytest bloom_test.py
Expected output
When run with the documented command, the program prints:
[True, False]
This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.
Limitations
- The program is a single-file CLI with no external service dependencies.
- Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
- Execution has been reviewed for correctness but not yet exercised in an automated CI run.