/// <exception cref="System.Exception"/> private void CheckMembershipVaryingSizedKeys(string name, IList <Text> keys) { FileSystem fs = FileSystem.GetLocal(conf); Path qualifiedDirName = fs.MakeQualified(TestDir); BloomMapFile.Writer writer = null; BloomMapFile.Reader reader = null; try { writer = new BloomMapFile.Writer(conf, fs, qualifiedDirName.ToString(), typeof(Text ), typeof(NullWritable)); foreach (Text key in keys) { writer.Append(key, NullWritable.Get()); } writer.Close(); // will check for membership in opposite order of how keys were inserted reader = new BloomMapFile.Reader(fs, qualifiedDirName.ToString(), conf); Collections.Reverse(keys); foreach (Text key_1 in keys) { Assert.True("False negative for existing key " + key_1, reader. ProbablyHasKey(key_1)); } reader.Close(); fs.Delete(qualifiedDirName, true); } finally { IOUtils.Cleanup(null, writer, reader); } }
/// <exception cref="System.Exception"/> public virtual void TestMembershipTest() { // write the file FileSystem fs = FileSystem.GetLocal(conf); Path qualifiedDirName = fs.MakeQualified(TestDir); conf.SetInt("io.mapfile.bloom.size", 2048); BloomMapFile.Writer writer = null; BloomMapFile.Reader reader = null; try { writer = new BloomMapFile.Writer(conf, fs, qualifiedDirName.ToString(), typeof(IntWritable ), typeof(Text)); IntWritable key = new IntWritable(); Text value = new Text(); for (int i = 0; i < 2000; i += 2) { key.Set(i); value.Set("00" + i); writer.Append(key, value); } writer.Close(); reader = new BloomMapFile.Reader(fs, qualifiedDirName.ToString(), conf); // check false positives rate int falsePos = 0; int falseNeg = 0; for (int i_1 = 0; i_1 < 2000; i_1++) { key.Set(i_1); bool exists = reader.ProbablyHasKey(key); if (i_1 % 2 == 0) { if (!exists) { falseNeg++; } } else { if (exists) { falsePos++; } } } reader.Close(); fs.Delete(qualifiedDirName, true); System.Console.Out.WriteLine("False negatives: " + falseNeg); Assert.Equal(0, falseNeg); System.Console.Out.WriteLine("False positives: " + falsePos); Assert.True(falsePos < 2); } finally { IOUtils.Cleanup(null, writer, reader); } }