Beispiel #1
0
        public void TestCuckooTestAndRemove()
        {
            var f = new CuckooBloomFilter(100, 0.1);

            // 'a' is not in the filter.
            if (f.Test(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }

            f.Add(A_BYTES);

            // 'a' is now in the filter.
            if (!f.TestAndRemove(A_BYTES))
            {
                Assert.Fail("'a' should be a member");
            }

            // 'a' is no longer in the filter.
            if (f.Test(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }
        }
Beispiel #2
0
        public void BenchmarkCuckooTest()
        {
            var n    = 100000u;
            var f    = new CuckooBloomFilter(n, 0.1);
            var data = new byte[n][];

            for (int i = 0; i < n; i++)
            {
                data[i] = Encoding.ASCII.GetBytes(i.ToString());
            }

            for (int i = 0; i < n; i++)
            {
                f.Test(data[i]);
            }
        }
Beispiel #3
0
        public void TestCuckooTestAndAdd()
        {
            var f = new CuckooBloomFilter(100, 0.1);

            // 'a' is not in the filter.
            if (f.Test(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }

            if (!f.Add(A_BYTES))
            {
                Assert.Fail("Should return true");
            }

            // 'a' is now in the filter.
            if (!f.Test(A_BYTES))
            {
                Assert.Fail("'a' should be a member");
            }

            // 'a' is still in the filter.
            var testAndAdd = f.TestAndAdd(A_BYTES);

            if (!testAndAdd.WasAlreadyAMember)
            {
                Assert.Fail("'a' should be a member");
            }
            // Should not have added
            Assert.IsFalse(testAndAdd.Added);

            // 'b' is not in the filter.
            testAndAdd = f.TestAndAdd(B_BYTES);
            if (testAndAdd.WasAlreadyAMember)
            {
                Assert.Fail("'b' should not be a member");
            }
            // Should add
            Assert.IsTrue(testAndAdd.Added);

            // 'a' is still in the filter.
            if (!f.Test(A_BYTES))
            {
                Assert.Fail("'a' should be a member");
            }

            // 'b' is now in the filter.
            if (!f.Test(B_BYTES))
            {
                Assert.Fail("'b' should be a member");
            }

            // 'c' is not in the filter.
            if (f.Test(C_BYTES))
            {
                Assert.Fail("'c' should not be a member");
            }

            for (int i = 0; i < 10000; i++)
            {
                f.Add(Encoding.ASCII.GetBytes(i.ToString()));
            }

            // Filter should be full.
            testAndAdd = f.TestAndAdd(X_BYTES);
            // Make sure not there
            Assert.IsFalse(testAndAdd.WasAlreadyAMember);
            // Make sure didn't add
            Assert.IsFalse(testAndAdd.Added);
        }