public void TestScalableBloomReset() { var f = new ScalableBloomFilter(10, 0.1, 0.8); for (int i = 0; i < 1000; i++) { f.Add(Encoding.ASCII.GetBytes(i.ToString())); } var count = f.Filters.Count; Assert.IsTrue(count > 1, string.Format("Expected more than 1 filter, got {0}", count)); var resetF = f.Reset(); Assert.AreSame(f, resetF, "Returned ScalableBloomFilter should be the same instance"); count = f.Filters.Count; Assert.IsTrue(count == 1, string.Format("Expected 1 filter, got {0}", count)); foreach (var partition in f.Filters[0].Partitions) { for (uint i = 0; i < partition.count; i++) { if (partition.Get(i) != 0) { Assert.Fail("Expected all bits to be unset"); } } } }
public void Contains_WhenItemHasBeenAdded_ShouldReturnTrue() { var filter = new ScalableBloomFilter <int>(0.02); filter.Add(42); Assert.True(filter.Contains(42)); }
public void ScalableBloomFilterCorrectlyActsAsASet() { IBloomFilter <int> filter = new ScalableBloomFilter <int>(0.9, 10, 0.001); //10 cannot already be in the collection, so inserting it must succeed Assert.IsFalse(filter.Add(10)); //10 is in the collection Assert.IsTrue(filter.Contains(10)); //check a load more numbers for (int i = 0; i < 100; i++) { filter.Add(i); Assert.IsTrue(filter.Contains(i)); } }
private void GeneralSetup(IByteConverter <ComplexType> byteConverter) { _bloomFilter = new ScalableBloomFilter <ComplexType>(0.02, byteConverter); foreach (var complexType in CreateComplexTypes()) { _bloomFilter.Add(complexType); } }
private void GeneralSetup(IByteConverter <string> byteConverter, int itemsToInsert) { _bloomFilter = new ScalableBloomFilter <string>(MaximumErrorRate, byteConverter); for (var i = 0; i < itemsToInsert; i++) { var s = $"string-{i + 1}"; _bloomFilter.Add(s); } }
public void NumberFilters_WithThreeTimesFirstCapacity_ShouldBeTwo() { var filter = new ScalableBloomFilter <int>(0.02); for (var i = 0; i < 3 * ScalableBloomFilter <int> .MinimumCapacity; i++) { filter.Add(i); } Assert.Equal(2, filter.NumberFilters); }
public void Setup_ScalableBloomFilter() { _regularScalableBloomFilter = new ScalableBloomFilter <string>(MaximumErrorRate, ByteConverter); for (var i = 0; i < ItemsToInsert; i++) { var s = $"string-{i + 1}"; _regularScalableBloomFilter.Add(s); } }
public void ClearingScalabeBloomFilterResetsEverything() { ScalableBloomFilter <int> filter = new ScalableBloomFilter <int>(0.9, 1000, 0.001); //Add a load of numbers for (int i = 0; i < 100; i++) { filter.Add(i); Assert.IsTrue(filter.Contains(i)); } Assert.AreEqual(100, filter.Count); filter.Clear(); Assert.AreEqual(0, filter.Count); //Add them again for (int i = 0; i < 100; i++) { filter.Add(i); Assert.IsTrue(filter.Contains(i)); } Assert.AreEqual(100, filter.Count); }
public void Contains_WhenItemHasBeenAdded_AndFilterHasBeenSerializedAndUnserialized_ShouldReturnTrue() { using (var stream = new MemoryStream()) { var filterOld = new ScalableBloomFilter <int>(0.02, ByteConverter); filterOld.Add(42); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, filterOld); stream.Flush(); stream.Position = 0; ScalableBloomFilter <int> filterNew = (ScalableBloomFilter <int>)formatter.Deserialize(stream); Assert.True(filterNew.Contains(42)); } }
public void BenchmarkScalableBloomAdd() { var n = 100000; var f = new ScalableBloomFilter(100000, 0.1, 0.8); 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.Add(data[i]); } }
public void TestScalableFillRatio() { var f = new ScalableBloomFilter(100, 0.1, 0.8); f.SetHash(ProbabilisticDataStructures.Defaults.GetDefaultHashAlgorithm()); for (int i = 0; i < 200; i++) { f.Add(Encoding.ASCII.GetBytes(i.ToString())); } var fillRatio = f.FillRatio(); if (fillRatio > 0.5) { Assert.Fail(string.Format("Expected less than or equal to 0.5, got {0}", fillRatio)); } }
public void ScalableBloomFilterCorrectlyActsAsASet() { IBloomFilter<int> filter = new ScalableBloomFilter<int>(0.9, 10, 0.001); //10 cannot already be in the collection, so inserting it must succeed Assert.IsFalse(filter.Add(10)); //10 is in the collection Assert.IsTrue(filter.Contains(10)); //check a load more numbers for (int i = 0; i < 100; i++) { filter.Add(i); Assert.IsTrue(filter.Contains(i)); } }
public void AddItemsThenCount_ScalableBloomFilter() { var count = 0; for (var i = 0; i < ItemsToInsert; i++) { var s = $"string-{i + 1}"; if (_scalableBloomFilter.Contains(s)) { continue; } count++; _scalableBloomFilter.Add(s); } var x = count; }
public void TestScalableBloomTestAndAdd() { var f = new ScalableBloomFilter(1000, 0.01, 0.8); // '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 ScalableBloomFilter 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 < 10000; i++) { f.TestAndAdd(Encoding.ASCII.GetBytes(i.ToString())); } // 'x' should not be a false positive. if (f.Test(X_BYTES)) { Assert.Fail("'x' should be a member"); } }
public void ClearingScalabeBloomFilterResetsEverything() { ScalableBloomFilter<int> filter = new ScalableBloomFilter<int>(0.9, 1000, 0.001); //Add a load of numbers for (int i = 0; i < 100; i++) { filter.Add(i); Assert.IsTrue(filter.Contains(i)); } Assert.AreEqual(100, filter.Count); filter.Clear(); Assert.AreEqual(0, filter.Count); //Add them again for (int i = 0; i < 100; i++) { filter.Add(i); Assert.IsTrue(filter.Contains(i)); } Assert.AreEqual(100, filter.Count); }