Example #1
0
    def test_c_cuckoo_filter_frombytes(self):
        """test initializing a counting cuckoo filter frombytes"""
        cko = CountingCuckooFilter(capacity=1000, bucket_size=2, auto_expand=False)
        for i in range(100):
            cko.add(str(i))
        bytes_out = bytes(cko)

        cko2 = CountingCuckooFilter.frombytes(bytes_out)

        self.assertEqual(bytes_out, bytes(cko2))
        for i in range(100):
            self.assertTrue(cko2.check(str(i)))
        self.assertFalse(cko2.check("999"))
Example #2
0
    def test_c_cuckoo_filter_er_frombytes(self):
        """test initializing a couting cuckoo filter from bytes"""
        cko = CountingCuckooFilter.init_error_rate(0.00001, capacity=3000)
        for i in range(1000):
            cko.add(str(i))
        bytes_out = bytes(cko)

        cko2 = CountingCuckooFilter.frombytes(bytes_out, error_rate=0.00001)

        self.assertEqual(bytes_out, bytes(cko2))
        for i in range(1000):
            self.assertTrue(cko2.check(str(i)))
        self.assertFalse(cko2.check("9999"))
        self.assertEqual(cko2.capacity, 3000)