コード例 #1
0
        public void TestCountingK()
        {
            var f = CountingBloomFilter.NewDefaultCountingBloomFilter(100, 0.1);
            var k = f.K();

            Assert.AreEqual(4u, k);
        }
コード例 #2
0
        public void TestCountingCapacity()
        {
            var f        = CountingBloomFilter.NewDefaultCountingBloomFilter(100, 0.1);
            var capacity = f.Capacity();

            Assert.AreEqual(480u, capacity);
        }
コード例 #3
0
        public void BenchmarkCountingTestAndRemove()
        {
            var n    = 100000;
            var f    = CountingBloomFilter.NewDefaultCountingBloomFilter(100000, 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.TestAndRemove(data[i]);
            }
        }
コード例 #4
0
        public void TestCountingCount()
        {
            var f = CountingBloomFilter.NewDefaultCountingBloomFilter(100, 0.1);

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

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

            var count = f.Count();

            Assert.AreEqual(5u, count);
        }
コード例 #5
0
        public void TestCountingReset()
        {
            var f = CountingBloomFilter.NewDefaultCountingBloomFilter(100, 0.1);

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

            var resetF = f.Reset();

            Assert.AreSame(f, resetF, "Returned CountingBloomFilter should be the same instance");

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

            Assert.AreEqual(0u, f.Count());
        }
コード例 #6
0
        public void TestCountingTestAndRemove()
        {
            var f = CountingBloomFilter.NewDefaultCountingBloomFilter(100, 0.01);

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

            f.Add(Encoding.ASCII.GetBytes("a"));

            // '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.TestAndRemove(A_BYTES))
            {
                Assert.Fail("'a' should not be a member");
            }
        }
コード例 #7
0
        public void TestCountingTestAndAdd()
        {
            var f = CountingBloomFilter.NewDefaultCountingBloomFilter(100, 0.01);

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

            var addedF = f.Add(A_BYTES);

            Assert.AreSame(f, addedF, "Returned BloomFilter should be the same instance");

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

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

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

            // '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 < 1000000; i++)
            {
                f.TestAndAdd(Encoding.ASCII.GetBytes(i.ToString()));
            }

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