예제 #1
0
    def test_rbf_rotate(self):
        ''' test that the bloom filter rotates the first bloom off the stack '''
        blm = RotatingBloomFilter(est_elements=10,
                                  false_positive_rate=0.05,
                                  max_queue_size=5)
        self.assertEqual(blm.expansions, 0)
        blm.add('test')
        self.assertEqual(blm.expansions, 0)
        for i in range(10):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.expansions, 1)
        self.assertEqual(blm.current_queue_size, 2)
        self.assertEqual(blm.check('test'), True)

        for i in range(10, 20):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), True)
        self.assertEqual(blm.current_queue_size, 3)

        for i in range(20, 30):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), True)
        self.assertEqual(blm.current_queue_size, 4)

        for i in range(30, 40):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), True)
        self.assertEqual(blm.current_queue_size, 5)

        for i in range(40, 50):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), False)  # it should roll off
        self.assertEqual(blm.current_queue_size, 5)
예제 #2
0
    def test_rbf_rotate(self):
        ''' test that the bloom filter rotates the first bloom off the stack '''
        blm = RotatingBloomFilter(est_elements=10, false_positive_rate=0.05,
                                  max_queue_size=5)
        self.assertEqual(blm.expansions, 0)
        blm.add('test')
        self.assertEqual(blm.expansions, 0)
        for i in range(10):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.expansions, 1)
        self.assertEqual(blm.current_queue_size, 2)
        self.assertEqual(blm.check('test'), True)

        for i in range(10, 20):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), True)
        self.assertEqual(blm.current_queue_size, 3)

        for i in range(20, 30):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), True)
        self.assertEqual(blm.current_queue_size, 4)

        for i in range(30, 40):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), True)
        self.assertEqual(blm.current_queue_size, 5)

        for i in range(40, 50):
            blm.add('{}'.format(i), force=True)
        self.assertEqual(blm.check('test'), False)  # it should roll off
        self.assertEqual(blm.current_queue_size, 5)
예제 #3
0
    def test_rfb_from_bytes(self):
        """basic rotating Bloom Filter export bytes test"""
        blm = RotatingBloomFilter(est_elements=25, false_positive_rate=0.05, max_queue_size=3)
        for i in range(105):
            blm.add(str(i))
        bytes_out = bytes(blm)

        blm2 = RotatingBloomFilter.frombytes(bytes_out, max_queue_size=3)
        self.assertEqual(blm2.expansions, 2)
        self.assertEqual(blm2.false_positive_rate, 0.05000000074505806)
        self.assertEqual(blm2.estimated_elements, 25)
        self.assertEqual(blm2.elements_added, 105)
        self.assertEqual(blm2.current_queue_size, 3)
        self.assertEqual(bytes(blm2), bytes(blm))
        for i in range(105):
            self.assertEqual(blm.check(str(i)), blm2.check(str(i)))