Ejemplo n.º 1
0
        public void with_something_hashed_probability_is_calculated_reasonably()
        {
            var filter = BloomFilter.FromManagedArray(1024, new IHasher[] { new Murmur2Unsafe(), new XXHashUnsafe() });

            filter.Add(Encoding.ASCII.GetBytes("Hi There"));
            Assert.IsTrue(filter.ProbabilityOfFalsePositive < 0.000001);
        }
Ejemplo n.º 2
0
        public void when_adding_a_string_it_does_not_contain_another()
        {
            var filter = BloomFilter.FromManagedArray(4096, new IHasher[] { new Murmur2Unsafe(), new XXHashUnsafe() });

            filter.Add("Hello There");
            Assert.IsFalse(filter.Contains("Hi There"));
        }
Ejemplo n.º 3
0
        public void when_adding_a_value_it_contains_it()
        {
            var filter = BloomFilter.FromManagedArray(4096, new IHasher[] { new Murmur2Unsafe(), new XXHashUnsafe() });

            filter.Add(Encoding.ASCII.GetBytes("Hello There"));
            Assert.IsTrue(filter.Contains(Encoding.ASCII.GetBytes("Hello There")));
        }
Ejemplo n.º 4
0
        private unsafe static void ManagedMemory()
        {
            Console.WriteLine("Managed Memory");
            const int size = (int)(500 * MEGABYTE);

            var watch = new Stopwatch();

            watch.Start();
            var filter = BloomFilter.FromManagedArray(size, new IHasher[] { new Murmur3AUnsafe(), new XXHashUnsafe() });

            for (int i = 0; i < 1000000; i++)
            {
                var bytes = Guid.NewGuid().ToByteArray();
                filter.Add(bytes);
                if (!filter.Contains(bytes))
                {
                    throw new Exception("broken");
                }
                if (i % 100000 == 0)
                {
                    Console.Write(".");
                }
            }
            Console.WriteLine();
            Console.WriteLine(watch.Elapsed);
        }
Ejemplo n.º 5
0
        public void when_hashing_two_items_the_hashed_items_should_be_two()
        {
            var filter = BloomFilter.FromManagedArray(4096, new IHasher[] { new Murmur2Unsafe(), new XXHashUnsafe() });

            filter.Add(Encoding.ASCII.GetBytes("Hello There"));
            filter.Add(Encoding.ASCII.GetBytes("Hi There"));
            Assert.AreEqual(2, filter.HashedItems);
        }
Ejemplo n.º 6
0
        public void with_nothing_hashed_probability_of_false_positive_is_zero()
        {
            var filter = BloomFilter.FromManagedArray(4096, new IHasher[] { new Murmur2Unsafe(), new XXHashUnsafe() });

            Assert.AreEqual(0, filter.ProbabilityOfFalsePositive);
        }