public void BloomFilterAddTest() { var addSize = 10000; var testData = DataGenerator.Generate().Take(addSize).ToArray(); var testData2 = DataGenerator.Generate().Skip(addSize).Take(addSize).ToArray(); var errorRate = 0.001F; var size = testData.Length; var configuration = new DefaultBloomFilterConfiguration(); var bloomFilter = new BloomFilter <TestEntity, long>(configuration); bloomFilter.Initialize(2 * size, errorRate); foreach (var itm in testData) { bloomFilter.Add(itm); } var bloomFilter2 = new BloomFilter <TestEntity, long>(configuration); bloomFilter2.Initialize(2 * size, errorRate); foreach (var itm in testData2) { bloomFilter2.Add(itm); } bloomFilter.Add(bloomFilter2); var contained = testData.Union(testData2).Count(item => bloomFilter.ContainsKey(item.Id)); Assert.AreEqual(contained, 2 * addSize, "Not all items found in added Bloom filters"); }
public void StandardCompressTest() { var addSize = 10000; var errorRate = 0.001F; var data = DataGenerator.Generate().Take(addSize).ToArray(); var filter = new BloomFilter <TestEntity, long>(new DefaultBloomFilterConfiguration()); filter.Initialize(data.Length, errorRate); foreach (var item in data) { filter.Add(item); } var basecount = DataGenerator .Generate() .Skip(addSize) .Take(addSize) .Count(itm => filter.ContainsKey(itm.Id)); Assert.IsTrue(basecount <= errorRate * addSize); filter.Initialize(50 * data.Length, errorRate); Assert.AreEqual(filter.Capacity, 500000, "Unexpected size of reverse Bloom filter."); foreach (var item in data) { filter.Add(item); } //check error rate. var notFoundCount = DataGenerator.Generate().Skip(addSize).Take(addSize).Count(itm => filter.Contains(itm)); Assert.IsTrue(notFoundCount <= basecount, "Uncompressed Bloom filter exceeded error rate."); Assert.IsTrue(data.All(d => filter.ContainsKey(d.Id)), "False negatives found in uncompressed filter"); filter = filter.Compress(true); Assert.AreEqual(filter.Capacity, 21739, "Unexpected size of compressed Bloom filter."); var compressNotFoundCount = DataGenerator.Generate().Skip(addSize).Take(addSize).Count(itm => filter.ContainsKey(itm.Id)); Assert.IsTrue(data.All(d => filter.ContainsKey(d.Id)), "False negatives found in compressed filter"); Assert.IsTrue(compressNotFoundCount <= basecount, "Compressed Bloom filter exceeded error rate."); }