Bug 705877 part 1. Rename mayContain on BloomFilter to mightContain. r=dbaron
--- a/mfbt/BloomFilter.h
+++ b/mfbt/BloomFilter.h
@@ -128,24 +128,24 @@ public:
void remove(const T* t);
/*
* Check whether the filter might contain an item. This can
* sometimes return true even if the item is not in the filter,
* 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);
static const uint32_t keyMask = (1 << KeySize) - 1;
static const uint32_t keyShift = 16;
static uint32_t hash1(uint32_t hash) { return hash & keyMask; }
static uint32_t hash2(uint32_t hash) { return (hash >> keyShift) & keyMask; }
@@ -208,25 +208,25 @@ MOZ_ALWAYS_INLINE void
BloomFilter<KeySize, T>::remove(const T* t)
{
uint32_t hash = t->hash();
remove(hash);
}
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);
}
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
#endif /* mozilla_BloomFilter_h_ */
--- a/xpcom/tests/TestBloomFilter.cpp
+++ b/xpcom/tests/TestBloomFilter.cpp
@@ -27,94 +27,94 @@ 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)) {
+ 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;
}
// 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)) {
+ if (!filter->mightContain(&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)) {
+ if (filter->mightContain(&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)) {
+ if (!filter->mightContain(&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)) {
+ 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;
}
return 0;
}