Exemplo n.º 1
0
 def test_remove(self):
     b = QuotientFilter(3, 13, hash_fn)
     for key in mock.keys():
         b.insert(key)
     for key in mock.keys():
         del b[key]
         self.assertFalse(key in b)
     self.assertEqual(0, len(b))
Exemplo n.º 2
0
 def test_iterator(self):
     b = QuotientFilter(3, 13, hash_fn)
     for key in mock.keys():
         b.insert(key)
     expected_cnt = len(mock)
     mock_values = mock.values()
     actual_cnt = 0
     for key in b:
         self.assertIn(key, mock_values)
         actual_cnt += 1
     self.assertEqual(actual_cnt, expected_cnt)
Exemplo n.º 3
0
 def test_setitem(self):
     b = QuotientFilter(3, 10, hash_fn)
     b[0] = 1023
     res = b.table[0]
     self.assertEqual(1023, res)
     b[1] = 1023
     res = b.table[0]
     val = (1023 << 13) + 1023
     self.assertEqual(val, res)
Exemplo n.º 4
0
 def test_getitem(self):
     b = QuotientFilter(3, 10, hash_fn)
     res = []
     hasher = Random(0).randrange
     for i in range(7):
         val = hasher(1023)
         b[i] = val
         res.append(val)
     for i in range(7):
         self.assertEqual(b[i], res[i])
Exemplo n.º 5
0
 def test_double_size(self):
     b = QuotientFilter(3, 13, hash_fn)
     for key in mock.keys():
         b.insert(key)
     b.double_size()
     expected_cnt = len(mock)
     mock_values = mock.values()
     actual_cnt = 0
     for key in b:
         self.assertIn(key, mock_values)
         actual_cnt += 1
     self.assertEqual(actual_cnt, expected_cnt)
     for key in mock.keys():
         self.assertTrue(key in b)
Exemplo n.º 6
0
 def test_create(self):
     cnt = 10**9
     qf = QuotientFilter.create(cnt, 0.02, hash_fn)
     self.assertEqual(24, qf.REMAINDER_BITS)
     self.assertEqual(6, qf.QUOTIENT_BITS)
Exemplo n.º 7
0
 def test_insert(self):
     b = QuotientFilter(3, 13, hash_fn)
     for key in mock.keys():
         b.insert(key)
     for key in mock.keys():
         self.assertTrue(key in b)
Exemplo n.º 8
0
 def test_init(self):
     b = QuotientFilter(3, 10, hash_fn)
     self.assertEqual(8, b.MAX_SIZE)