Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1170)

Unified Diff: third_party/WebKit/Source/wtf/BloomFilter.h

Issue 1611343002: wtf reformat test Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pydent Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/wtf/BitwiseOperations.h ('k') | third_party/WebKit/Source/wtf/ByteOrder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/BloomFilter.h
diff --git a/third_party/WebKit/Source/wtf/BloomFilter.h b/third_party/WebKit/Source/wtf/BloomFilter.h
index 1704a827473035a1516a64439ac45074d62cc184..0ce3f5fedd17b22e507dad63105f1abfbd4d5de1 100644
--- a/third_party/WebKit/Source/wtf/BloomFilter.h
+++ b/third_party/WebKit/Source/wtf/BloomFilter.h
@@ -37,103 +37,110 @@ namespace WTF {
// keys and m is the table size (==2^keyBits).
template <unsigned keyBits>
class BloomFilter {
- USING_FAST_MALLOC(BloomFilter);
-public:
- static_assert(keyBits <= 16, "bloom filter key size check");
+ USING_FAST_MALLOC(BloomFilter);
- static const size_t tableSize = 1 << keyBits;
- static const unsigned keyMask = (1 << keyBits) - 1;
- static uint8_t maximumCount() { return std::numeric_limits<uint8_t>::max(); }
+ public:
+ static_assert(keyBits <= 16, "bloom filter key size check");
- BloomFilter() { clear(); }
+ static const size_t tableSize = 1 << keyBits;
+ static const unsigned keyMask = (1 << keyBits) - 1;
+ static uint8_t maximumCount() { return std::numeric_limits<uint8_t>::max(); }
- void add(unsigned hash);
- void remove(unsigned hash);
+ BloomFilter() { clear(); }
- // The filter may give false positives (claim it may contain a key it doesn't)
- // but never false negatives (claim it doesn't contain a key it does).
- bool mayContain(unsigned hash) const { return firstSlot(hash) && secondSlot(hash); }
+ void add(unsigned hash);
+ void remove(unsigned hash);
- // The filter must be cleared before reuse even if all keys are removed.
- // Otherwise overflowed keys will stick around.
- void clear();
+ // The filter may give false positives (claim it may contain a key it doesn't)
+ // but never false negatives (claim it doesn't contain a key it does).
+ bool mayContain(unsigned hash) const {
+ return firstSlot(hash) && secondSlot(hash);
+ }
- void add(const AtomicString& string) { add(string.impl()->existingHash()); }
- void add(const String& string) { add(string.impl()->hash()); }
- void remove(const AtomicString& string) { remove(string.impl()->existingHash()); }
- void remove(const String& string) { remove(string.impl()->hash()); }
+ // The filter must be cleared before reuse even if all keys are removed.
+ // Otherwise overflowed keys will stick around.
+ void clear();
- bool mayContain(const AtomicString& string) const { return mayContain(string.impl()->existingHash()); }
- bool mayContain(const String& string) const { return mayContain(string.impl()->hash()); }
+ void add(const AtomicString& string) { add(string.impl()->existingHash()); }
+ void add(const String& string) { add(string.impl()->hash()); }
+ void remove(const AtomicString& string) {
+ remove(string.impl()->existingHash());
+ }
+ void remove(const String& string) { remove(string.impl()->hash()); }
+
+ bool mayContain(const AtomicString& string) const {
+ return mayContain(string.impl()->existingHash());
+ }
+ bool mayContain(const String& string) const {
+ return mayContain(string.impl()->hash());
+ }
#if ENABLE(ASSERT)
- // Slow.
- bool likelyEmpty() const;
- bool isClear() const;
+ // Slow.
+ bool likelyEmpty() const;
+ bool isClear() const;
#endif
-private:
- uint8_t& firstSlot(unsigned hash) { return m_table[hash & keyMask]; }
- uint8_t& secondSlot(unsigned hash) { return m_table[(hash >> 16) & keyMask]; }
- const uint8_t& firstSlot(unsigned hash) const { return m_table[hash & keyMask]; }
- const uint8_t& secondSlot(unsigned hash) const { return m_table[(hash >> 16) & keyMask]; }
-
- uint8_t m_table[tableSize];
+ private:
+ uint8_t& firstSlot(unsigned hash) { return m_table[hash & keyMask]; }
+ uint8_t& secondSlot(unsigned hash) { return m_table[(hash >> 16) & keyMask]; }
+ const uint8_t& firstSlot(unsigned hash) const {
+ return m_table[hash & keyMask];
+ }
+ const uint8_t& secondSlot(unsigned hash) const {
+ return m_table[(hash >> 16) & keyMask];
+ }
+
+ uint8_t m_table[tableSize];
};
template <unsigned keyBits>
-inline void BloomFilter<keyBits>::add(unsigned hash)
-{
- uint8_t& first = firstSlot(hash);
- uint8_t& second = secondSlot(hash);
- if (LIKELY(first < maximumCount()))
- ++first;
- if (LIKELY(second < maximumCount()))
- ++second;
+inline void BloomFilter<keyBits>::add(unsigned hash) {
+ uint8_t& first = firstSlot(hash);
+ uint8_t& second = secondSlot(hash);
+ if (LIKELY(first < maximumCount()))
+ ++first;
+ if (LIKELY(second < maximumCount()))
+ ++second;
}
template <unsigned keyBits>
-inline void BloomFilter<keyBits>::remove(unsigned hash)
-{
- uint8_t& first = firstSlot(hash);
- uint8_t& second = secondSlot(hash);
- ASSERT(first);
- ASSERT(second);
- // In case of an overflow, the slot sticks in the table until clear().
- if (LIKELY(first < maximumCount()))
- --first;
- if (LIKELY(second < maximumCount()))
- --second;
+inline void BloomFilter<keyBits>::remove(unsigned hash) {
+ uint8_t& first = firstSlot(hash);
+ uint8_t& second = secondSlot(hash);
+ ASSERT(first);
+ ASSERT(second);
+ // In case of an overflow, the slot sticks in the table until clear().
+ if (LIKELY(first < maximumCount()))
+ --first;
+ if (LIKELY(second < maximumCount()))
+ --second;
}
template <unsigned keyBits>
-inline void BloomFilter<keyBits>::clear()
-{
- memset(m_table, 0, tableSize);
+inline void BloomFilter<keyBits>::clear() {
+ memset(m_table, 0, tableSize);
}
#if ENABLE(ASSERT)
template <unsigned keyBits>
-bool BloomFilter<keyBits>::likelyEmpty() const
-{
- for (size_t n = 0; n < tableSize; ++n) {
- if (m_table[n] && m_table[n] != maximumCount())
- return false;
- }
- return true;
+bool BloomFilter<keyBits>::likelyEmpty() const {
+ for (size_t n = 0; n < tableSize; ++n) {
+ if (m_table[n] && m_table[n] != maximumCount())
+ return false;
+ }
+ return true;
}
template <unsigned keyBits>
-bool BloomFilter<keyBits>::isClear() const
-{
- for (size_t n = 0; n < tableSize; ++n) {
- if (m_table[n])
- return false;
- }
- return true;
+bool BloomFilter<keyBits>::isClear() const {
+ for (size_t n = 0; n < tableSize; ++n) {
+ if (m_table[n])
+ return false;
+ }
+ return true;
}
#endif
-
}
using WTF::BloomFilter;
« no previous file with comments | « third_party/WebKit/Source/wtf/BitwiseOperations.h ('k') | third_party/WebKit/Source/wtf/ByteOrder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698