本文整理汇总了C++中BloomFilter::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ BloomFilter::clear方法的具体用法?C++ BloomFilter::clear怎么用?C++ BloomFilter::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BloomFilter
的用法示例。
在下文中一共展示了BloomFilter::clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: one
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;
}
示例2: main
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;
}