Challenge: Implement a Bloom Filter
Aufgabe
Swipe to start coding
Implement a BloomFilter class that performs probabilistic membership testing using a bit array and multiple hash functions.
Your implementation must follow these rules:
- The filter uses a bit array of length
size, initialized with zeros. - The filter uses exactly
hash_counthash functions for each inserted item. - The private method
_hashes(item)must produce a list ofhash_countinteger indices, each in the range[0, size). - The
add(item)method must set all corresponding bits for the item’s hash indices. - The
contains(item)method returns:Trueif all bits for the item’s hash indices are setFalseotherwise
- The filter may have false positives, but must never produce false negatives (i.e., must never return
Falsefor an item that was previously added).
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 3. Kapitel 5
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Großartig!
Completion Rate verbessert auf 7.69
Challenge: Implement a Bloom Filter
Swipe um das Menü anzuzeigen
Aufgabe
Swipe to start coding
Implement a BloomFilter class that performs probabilistic membership testing using a bit array and multiple hash functions.
Your implementation must follow these rules:
- The filter uses a bit array of length
size, initialized with zeros. - The filter uses exactly
hash_counthash functions for each inserted item. - The private method
_hashes(item)must produce a list ofhash_countinteger indices, each in the range[0, size). - The
add(item)method must set all corresponding bits for the item’s hash indices. - The
contains(item)method returns:Trueif all bits for the item’s hash indices are setFalseotherwise
- The filter may have false positives, but must never produce false negatives (i.e., must never return
Falsefor an item that was previously added).
Lösung
War alles klar?
Danke für Ihr Feedback!
Abschnitt 3. Kapitel 5
single