Bug 705877 part 1. Rename mayContain on BloomFilter to mightContain. r=dbaron

This commit is contained in:
Boris Zbarsky 2012-03-12 22:54:12 -05:00
parent 739a9f7be8
commit 9801e6dd67
2 changed files with 17 additions and 17 deletions

View File

@ -133,14 +133,14 @@ public:
* but will never return false for items that are actually in the
* filter.
*/
bool mayContain(const T* t) const;
bool mightContain(const T* t) const;
/*
* Methods for add/remove/contain when we already have a hash computed
*/
void add(uint32_t hash);
void remove(uint32_t hash);
bool mayContain(uint32_t hash) const;
bool mightContain(uint32_t hash) const;
private:
static const size_t arraySize = (1 << KeySize);
@ -213,7 +213,7 @@ BloomFilter<KeySize, T>::remove(const T* t)
template<unsigned KeySize, class T>
MOZ_ALWAYS_INLINE bool
BloomFilter<KeySize, T>::mayContain(uint32_t hash) const
BloomFilter<KeySize, T>::mightContain(uint32_t hash) const
{
// Check that all the slots for this hash contain something
return firstSlot(hash) && secondSlot(hash);
@ -221,10 +221,10 @@ BloomFilter<KeySize, T>::mayContain(uint32_t hash) const
template<unsigned KeySize, class T>
MOZ_ALWAYS_INLINE bool
BloomFilter<KeySize, T>::mayContain(const T* t) const
BloomFilter<KeySize, T>::mightContain(const T* t) const
{
uint32_t hash = t->hash();
return mayContain(hash);
return mightContain(hash);
}
} // namespace mozilla

View File

@ -32,30 +32,30 @@ int main()
FilterChecker multiple(0x20001);
filter->add(&one);
if (!filter->mayContain(&one)) {
if (!filter->mightContain(&one)) {
fail("Filter should contain 'one'");
return -1;
}
if (filter->mayContain(&multiple)) {
if (filter->mightContain(&multiple)) {
fail("Filter claims to contain 'multiple' when it should not");
return -1;
}
if (!filter->mayContain(&many)) {
if (!filter->mightContain(&many)) {
fail("Filter should contain 'many' (false positive)");
return -1;
}
filter->add(&two);
if (!filter->mayContain(&multiple)) {
if (!filter->mightContain(&multiple)) {
fail("Filter should contain 'multiple' (false positive)");
return -1;
}
// Test basic removals
filter->remove(&two);
if (filter->mayContain(&multiple)) {
if (filter->mightContain(&multiple)) {
fail("Filter claims to contain 'multiple' when it should not after two was "
"removed");
return -1;
@ -66,7 +66,7 @@ int main()
for (unsigned i = 0; i < FILTER_SIZE - 1; ++i) {
filter->add(&two);
}
if (!filter->mayContain(&multiple)) {
if (!filter->mightContain(&multiple)) {
fail("Filter should contain 'multiple' after 'two' added lots of times "
"(false positive)");
return -1;
@ -74,7 +74,7 @@ int main()
for (unsigned i = 0; i < FILTER_SIZE - 1; ++i) {
filter->remove(&two);
}
if (filter->mayContain(&multiple)) {
if (filter->mightContain(&multiple)) {
fail("Filter claims to contain 'multiple' when it should not after two was "
"removed lots of times");
return -1;
@ -84,7 +84,7 @@ int main()
for (unsigned i = 0; i < FILTER_SIZE + 1; ++i) {
filter->add(&two);
}
if (!filter->mayContain(&multiple)) {
if (!filter->mightContain(&multiple)) {
fail("Filter should contain 'multiple' after 'two' added lots more times "
"(false positive)");
return -1;
@ -92,26 +92,26 @@ int main()
for (unsigned i = 0; i < FILTER_SIZE + 1; ++i) {
filter->remove(&two);
}
if (!filter->mayContain(&multiple)) {
if (!filter->mightContain(&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)) {
if (!filter->mightContain(&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)) {
if (filter->mightContain(&one)) {
fail("Filter should not contain 'one', because we didn't overflow its "
"bucket");
return -1;
}
filter->clear();
if (filter->mayContain(&multiple)) {
if (filter->mightContain(&multiple)) {
fail("clear() failed to work");
return -1;
}