static void Test1() { var count = 10_000_000; //var bf = new BloomFilter(count, 0.0001); var bf = new BloomFilter(count * 32); var rs1 = 0; var rs2 = 0; for (var i = 0; i < count; i++) { var key = $"ip_{i}"; if (bf.Get(key)) { rs1++; } else { bf.Set(key); rs2++; } } Console.WriteLine($" 存在:{rs1} {(Double)rs1 / count:p8}"); Console.WriteLine($"不存在:{rs2} {(Double)rs2 / count:p8}"); }
public void Test3() { XTrace.WriteLine("低精度1"); var count = 1_000_000; var bf = new BloomFilter(count / 10); var rs1 = 0; var rs2 = 0; for (var i = 0; i < count; i++) { var key = $"ip_{i}"; if (bf.Get(key)) { rs1++; } else { bf.Set(key); rs2++; } } var p1 = (Double)rs1 / count; var p2 = (Double)rs2 / count; XTrace.WriteLine($" 存在:{rs1} {p1:p8}"); XTrace.WriteLine($"不存在:{rs2} {p2:p8}"); //Assert.True(p1 < 0.06); //Assert.True(p2 > 0.94); var buf = bf.GetBytes(); XTrace.WriteLine("bf.Length={0:n0}", buf.Length); var str = bf.GetString(); XTrace.WriteLine("str.Length={0:n0}", str.Length); }
public void Test1() { XTrace.WriteLine("高精度1"); var count = 10_000_000; //var bf = new BloomFilter(count, 0.0001); var bf = new BloomFilter(count * 32); var rs1 = 0; var rs2 = 0; for (var i = 0; i < count; i++) { var key = $"ip_{i}"; if (bf.Get(key)) { rs1++; } else { bf.Set(key); rs2++; } } var p1 = (Double)rs1 / count; var p2 = (Double)rs2 / count; XTrace.WriteLine($" 存在:{rs1} {p1:p8}"); XTrace.WriteLine($"不存在:{rs2} {p2:p8}"); Assert.True(p1 < 0.00004); Assert.True(p2 > 0.99996); var buf = bf.GetBytes(); XTrace.WriteLine("bf.Length={0:n0}", buf.Length); }
public IEnumerable <string> GetChangedKeys() { return(BloomFilter.Get(this.GetType(), __masks__)); }