Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 705877 part 1. Rename mayContain on BloomFilter to mightContain. …
Browse files Browse the repository at this point in the history
…r=dbaron
  • Loading branch information
bzbarsky committed Mar 13, 2012
1 parent 1d4120a commit d09e76b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions mfbt/BloomFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ class BloomFilter {
* 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);
Expand Down Expand Up @@ -213,18 +213,18 @@ 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);
}

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
Expand Down
24 changes: 12 additions & 12 deletions xpcom/tests/TestBloomFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -66,15 +66,15 @@ 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;
}
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;
Expand All @@ -84,34 +84,34 @@ 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;
}
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;
}
Expand Down

0 comments on commit d09e76b

Please sign in to comment.