예제 #1
0
 def post(self):
   bloom = memcache.get("filter")
   if bloom is None:
     bloom = Bloom(2**21, 5)
   
   value = self.request.POST["value"]
   value_already_included = False
   if value in bloom:
     value_already_included = True
   bloom.add(value)
   memcache.set("filter", bloom)
   self.redirect("/?success=" + str(not value_already_included) 
                 + "&value=" + value)
예제 #2
0
class TestBloomMethods(unittest.TestCase):
    """Test the Bloom Filter."""
    def setUp(self):
        """Set up the Bloom Filter table."""
        self.size = 10
        self.b = Bloom(self.size)

    def test_add(self):
        """Make sure that add properly activates bits in the table."""
        self.b.add('Archimedes')
        self.assertEqual(self.b.table, [1, 0, 0, 1, 0, 0, 0, 0, 0, 0])

    def test_check_element_in_table(self):
        """Ensure check method returns true if element was added."""
        self.b.add('Copernicus')
        self.assertEqual(self.b.check('Copernicus'), True)

    def test_check_element_not_in_table(self):
        """Ensure check method returns false if elmt definitely not in set."""
        self.assertEqual(self.b.check('Galileo'), False)
예제 #3
0
def main():
    """Main function."""
    bloom = Bloom(12)

    # Add some values to the set
    bloom.add("Curie")
    bloom.add("Laplace")

    # Now test some values
    person = "Pasteur"
    if (bloom.check(person)):
        print("%s is probably in the set." % person)
    else:
        print("%s is definitely not in the set." % person)

    # Test some more values
    person = "Curie"
    if (bloom.check(person)):
        print("%s is probably in the set." % person)
    else:
        print("%s is definitely not in the set." % person)