From 54041ff38c8d7302e2492281e1f18ceac28ad03d Mon Sep 17 00:00:00 2001 From: isidroas Date: Sat, 8 Apr 2023 16:49:05 +0200 Subject: [PATCH] Update data_structures/hashing/bloom_filter.py Co-authored-by: Christian Clauss --- data_structures/hashing/bloom_filter.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/data_structures/hashing/bloom_filter.py b/data_structures/hashing/bloom_filter.py index 526833c01..fc599c3f8 100644 --- a/data_structures/hashing/bloom_filter.py +++ b/data_structures/hashing/bloom_filter.py @@ -29,22 +29,11 @@ because both hash functions return the same value '01100100' Not added elements should return False ... ->>> "The Goodfather" in bloom +>>> not_present_films = ("The Goodfather", "Interstellar", "Parasite", "Pulp Fiction") +>>> {film: bloom.format_hash(film) for film in not_present_films)} +{'The Goodfather': '00011000', 'Interstellar': '00000011', 'Parasite': '00010010': 'Pulp Fiction': '10000100'} +>>> any(film in bloom for film in not_present_films) False ->>> bloom.format_hash("The Goodfather") -'00011000' ->>> "Interstellar" in bloom -False ->>> bloom.format_hash("Interstellar") -'00000011' ->>> "Parasite" in bloom -False ->>> bloom.format_hash("Parasite") -'00010010' ->>> "Pulp Fiction" in bloom -False ->>> bloom.format_hash("Pulp Fiction") -'10000100' but sometimes there are false positives: >>> "Ratatouille" in bloom