Exemplo n.º 1
0
        public void TestStablePoint()
        {
            var f = StableBloomFilter.NewDefaultStableBloomFilter(10000, 0.1);

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

            var zeros = 0;

            for (uint i = 0; i < f.M; i++)
            {
                if (f.cells.Get(i) == 0)
                {
                    zeros++;
                }
            }

            var actual   = Math.Round((double)((double)zeros / (double)f.M), 1, MidpointRounding.AwayFromZero);
            var expected = Math.Round(f.StablePoint(), 1, MidpointRounding.AwayFromZero);

            Assert.AreEqual(expected, actual);

            // A classic Bloom filter is a special case of SBF where P is 0 and max is 1.
            // It doesn't have a stable point.
            var bf          = StableBloomFilter.NewUnstableBloomFilter(1000, 0.1);
            var stablePoint = bf.StablePoint();

            if (stablePoint != 0)
            {
                Assert.Fail(string.Format("Expected stable point 0, got {0}", stablePoint));
            }
        }
Exemplo n.º 2
0
 public void Testinitialize()
 {
     n    = 100000;
     f    = StableBloomFilter.NewUnstableBloomFilter(n, 0.1);
     data = new byte[n][];
     for (int i = 0; i < n; i++)
     {
         data[i] = Encoding.ASCII.GetBytes(i.ToString());
     }
 }
Exemplo n.º 3
0
        public void TestNewUnstableBloomFilter()
        {
            var f = StableBloomFilter.NewUnstableBloomFilter(100, 0.1);
            var k = ProbabilisticDataStructures.Utils.OptimalK(0.1);

            Assert.AreEqual(k, f.K());
            Assert.AreEqual(100u, f.M);
            Assert.AreEqual(0u, f.P());
            Assert.AreEqual(1u, f.Max);
        }
Exemplo n.º 4
0
        public void TestStableFalsePositiveRate()
        {
            var f   = StableBloomFilter.NewDefaultStableBloomFilter(1000, 0.01);
            var fps = Math.Round(f.FalsePositiveRate(), 2, MidpointRounding.AwayFromZero);

            Assert.IsFalse(fps > 0.01);

            // Classic Bloom filters have an unbound rate of false positives. Once they
            // become full, every query returns a false positive.
            var bf = StableBloomFilter.NewUnstableBloomFilter(1000, 0.01);

            fps = bf.FalsePositiveRate();
            Assert.AreEqual(1.0, fps);
        }