Beispiel #1
0
        public void TestDeletableReset()
        {
            var d = new DeletableBloomFilter(100, 10, 0.1);

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

            var resetF = d.Reset();

            Assert.AreSame(d, resetF, "Returned DeletableBloomFilter should be the same instance");

            for (uint i = 0; i < d.Buckets.count; i++)
            {
                if (d.Buckets.Get(i) != 0)
                {
                    Assert.Fail("Expected all bits to be unset");
                }
            }

            for (uint i = 0; i < d.Collisions.count; i++)
            {
                if (d.Collisions.Get(i) != 0)
                {
                    Assert.Fail("Expected all bits to be unset");
                }
            }

            var count = d.Count();

            Assert.AreEqual(0u, count);
        }
Beispiel #2
0
        public void BenchmarkDeletableAdd()
        {
            var n    = 100000;
            var d    = new DeletableBloomFilter(100, 10, 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++)
            {
                d.Add(data[i]);
            }
        }
Beispiel #3
0
        public void TestDeletableCount()
        {
            var d = new DeletableBloomFilter(100, 10, 0.1);

            for (uint i = 0; i < 10; i++)
            {
                d.Add(Encoding.ASCII.GetBytes(i.ToString()));
            }

            for (int i = 0; i < 5; i++)
            {
                d.TestAndRemove(Encoding.ASCII.GetBytes(i.ToString()));
            }

            var count = d.Count();

            Assert.AreEqual(5u, count);
        }
Beispiel #4
0
        public void TestDeletableTestAndRemove()
        {
            var d = new DeletableBloomFilter(100, 10, 0.1);

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

            d.Add(A_BYTES);

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

            // 'a' is no longer in the filter.
            if (d.TestAndRemove(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }
        }
Beispiel #5
0
        public void TestDeletableTestAndAdd()
        {
            var d = new DeletableBloomFilter(100, 10, 0.1);

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

            var addedF = d.Add(A_BYTES);

            Assert.AreSame(d, addedF, "Returned CountingBloomFilter should be the same instance");

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

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

            // 'b' is not in the filter.
            if (d.TestAndAdd(B_BYTES))
            {
                Assert.Fail("'b' should not be a member");
            }

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

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

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

            for (int i = 0; i < 1000000; i++)
            {
                d.TestAndAdd(Encoding.ASCII.GetBytes(i.ToString()));
            }

            // 'x' should be a false positive.
            if (!d.Test(X_BYTES))
            {
                Assert.Fail("'x' should be a member");
            }
        }