TEST(BloomFilterTest, NumEntriesAndFalsePositiveRate)
{
  BloomFilter* bf = BloomFilter::for_num_entries_and_fp_prob(2, 0.0001);

  bf->add("Kermit");
  bf->add("MissPiggy");

  EXPECT_TRUE(bf->check("Kermit"));
  EXPECT_TRUE(bf->check("MissPiggy"));
  EXPECT_FALSE(bf->check("Gonzo"));
  EXPECT_FALSE(bf->check("Animal"));

  delete bf; bf = nullptr;
}
int main() {
	
	BloomFilter *s = new BloomFilter(4);
	char c;
	//cout<<"BLABLA";
	Key k;
	do {
		cout<<"a - add\nf - find\nd - del\nq - quit\n";
		cin>>c;
		if (!(c!='a' || c!='f' || c!='d' || c!='q'))
			continue;
		cout<<"Value:\n";
		cin>>k;
		if(c=='a') {
			
			s->add(k);
		} else if(c == 'f') {
			
			if((s->testExist(k, false)))
				cout<<"Found!\n";
			else
				cout<<"Nod found!\n";
			
		} else if(c == 'd') {
			s->del(k);
		} else {
			break;
		}
			}while(c!='q');
	cout<<"That's all, folks!\n";
	return 0;
}
Beispiel #3
0
int main()
{
    BloomFilter bf;

    bf.add("hoge");
    bf.add("fuga");

    cout << (bf.exist("hoge") ? "true" : "false") << endl;
    cout << (bf.exist("fuga") ? "true" : "false") << endl;
    cout << (bf.exist("kuso") ? "true" : "false") << endl;

    return 0;
}
Beispiel #4
0
int main(){
  BloomFilter *bf = new BloomFilter(1024);

  string st1 = "this";
  string st2 = "is";
  string st3 = "a";
  string st4 = "test";

  bf->add(st1.c_str(),st1.length());
  bf->add(st2.c_str(),st2.length());
  cout<<"bloom filter contains \""<<st1 <<"\"" <<":"<< bf->contains(st1.c_str(), st1.length()) << endl;
  cout<<"bloom filter contains \""<<st2 <<"\"" <<":"<< bf->contains(st2.c_str(), st2.length()) << endl;
  cout<<"bloom filter contains \""<<st3 <<"\"" <<":"<< bf->contains(st3.c_str(), st3.length()) << endl;
  cout<<"bloom filter contains \""<<st4 <<"\"" <<":"<< bf->contains(st4.c_str(), st4.length()) << endl;


}
Beispiel #5
0
int
main()
{
  BloomFilter<12, FilterChecker> *filter = new BloomFilter<12, FilterChecker>();
  MOZ_RELEASE_ASSERT(filter);

  FilterChecker one(1);
  FilterChecker two(0x20000);
  FilterChecker many(0x10000);
  FilterChecker multiple(0x20001);

  filter->add(&one);
  MOZ_RELEASE_ASSERT(filter->mightContain(&one),
             "Filter should contain 'one'");

  MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
             "Filter claims to contain 'multiple' when it should not");

  MOZ_RELEASE_ASSERT(filter->mightContain(&many),
             "Filter should contain 'many' (false positive)");

  filter->add(&two);
  MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
             "Filter should contain 'multiple' (false positive)");

  // Test basic removals
  filter->remove(&two);
  MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
             "Filter claims to contain 'multiple' when it should not after two "
             "was removed");

  // Test multiple addition/removal
  const size_t FILTER_SIZE = 255;
  for (size_t i = 0; i < FILTER_SIZE - 1; ++i)
    filter->add(&two);

  MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
             "Filter should contain 'multiple' after 'two' added lots of times "
             "(false positive)");

  for (size_t i = 0; i < FILTER_SIZE - 1; ++i)
    filter->remove(&two);

  MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
             "Filter claims to contain 'multiple' when it should not after two "
             "was removed lots of times");

  // Test overflowing the filter buckets
  for (size_t i = 0; i < FILTER_SIZE + 1; ++i)
    filter->add(&two);

  MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
             "Filter should contain 'multiple' after 'two' added lots more "
             "times (false positive)");

  for (size_t i = 0; i < FILTER_SIZE + 1; ++i)
    filter->remove(&two);

  MOZ_RELEASE_ASSERT(filter->mightContain(&multiple),
             "Filter claims to not contain 'multiple' even though we should "
             "have run out of space in the buckets (false positive)");
  MOZ_RELEASE_ASSERT(filter->mightContain(&two),
             "Filter claims to not contain 'two' even though we should have "
             "run out of space in the buckets (false positive)");

  filter->remove(&one);

  MOZ_RELEASE_ASSERT(!filter->mightContain(&one),
             "Filter should not contain 'one', because we didn't overflow its "
             "bucket");

  filter->clear();

  MOZ_RELEASE_ASSERT(!filter->mightContain(&multiple),
             "clear() failed to work");

  return 0;
}
int main()
{
  BloomFilter<12, FilterChecker> *filter = new BloomFilter<12, FilterChecker>();

  FilterChecker one(1);
  FilterChecker two(0x20000);
  FilterChecker many(0x10000);
  FilterChecker multiple(0x20001);

  filter->add(&one);
  if (!filter->mayContain(&one)) {
    fail("Filter should contain 'one'");
    return -1;
  }

  if (filter->mayContain(&multiple)) {
    fail("Filter claims to contain 'multiple' when it should not");
    return -1;
  }

  if (!filter->mayContain(&many)) {
    fail("Filter should contain 'many' (false positive)");
    return -1;
  }

  filter->add(&two);
  if (!filter->mayContain(&multiple)) {
    fail("Filter should contain 'multiple' (false positive)");
    return -1;
  }

  // Test basic removals
  filter->remove(&two);
  if (filter->mayContain(&multiple)) {
    fail("Filter claims to contain 'multiple' when it should not after two was "
         "removed");
    return -1;
  }

  // Test multiple addition/removal
  const unsigned FILTER_SIZE = 255;
  for (unsigned i = 0; i < FILTER_SIZE - 1; ++i) {
    filter->add(&two);
  }
  if (!filter->mayContain(&multiple)) {
    fail("Filter should contain 'multiple' after 'two' added lots of times "
         "(false positive)");
    return -1;
  }
  for (unsigned i = 0; i < FILTER_SIZE - 1; ++i) {
    filter->remove(&two);
  }
  if (filter->mayContain(&multiple)) {
    fail("Filter claims to contain 'multiple' when it should not after two was "
         "removed lots of times");
    return -1;
  }

  // Test overflowing the filter buckets
  for (unsigned i = 0; i < FILTER_SIZE + 1; ++i) {
    filter->add(&two);
  }
  if (!filter->mayContain(&multiple)) {
    fail("Filter should contain 'multiple' after 'two' added lots more times "
         "(false positive)");
    return -1;
  }
  for (unsigned i = 0; i < FILTER_SIZE + 1; ++i) {
    filter->remove(&two);
  }
  if (!filter->mayContain(&multiple)) {
    fail("Filter claims to not contain 'multiple' even though we should have "
         "run out of space in the buckets (false positive)");
    return -1;
  }
  if (!filter->mayContain(&two)) {
    fail("Filter claims to not contain 'two' even though we should have run "
         "out of space in the buckets (false positive)");
    return -1;
  }

  filter->remove(&one);
  if (filter->mayContain(&one)) {
    fail("Filter should not contain 'one', because we didn't overflow its "
         "bucket");
    return -1;
  }
  
  filter->clear();
  if (filter->mayContain(&multiple)) {
    fail("clear() failed to work");
    return -1;
  }

  return 0;
}