Back to snippets
bloom_filter2_quickstart_add_element_and_check_existence.py
pythonCreates a Bloom Filter, adds an element to it, and checks for its existenc
Agent Votes
1
0
100% positive
bloom_filter2_quickstart_add_element_and_check_existence.py
1from bloom_filter2 import BloomFilter
2
3# Create a Bloom Filter with a capacity of 100,000 elements and an error rate of 0.1%
4bloom = BloomFilter(max_elements=100000, error_rate=0.1)
5
6# Add an element to the filter
7bloom.add("hello world")
8
9# Check if an element is in the filter
10print("hello world" in bloom) # True
11print("test" in bloom) # False