OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 void clear(); | 57 void clear(); |
58 | 58 |
59 void add(const AtomicString& string) { add(string.impl()->existingHash()); } | 59 void add(const AtomicString& string) { add(string.impl()->existingHash()); } |
60 void add(const String& string) { add(string.impl()->hash()); } | 60 void add(const String& string) { add(string.impl()->hash()); } |
61 void remove(const AtomicString& string) { remove(string.impl()->existingHash
()); } | 61 void remove(const AtomicString& string) { remove(string.impl()->existingHash
()); } |
62 void remove(const String& string) { remove(string.impl()->hash()); } | 62 void remove(const String& string) { remove(string.impl()->hash()); } |
63 | 63 |
64 bool mayContain(const AtomicString& string) const { return mayContain(string
.impl()->existingHash()); } | 64 bool mayContain(const AtomicString& string) const { return mayContain(string
.impl()->existingHash()); } |
65 bool mayContain(const String& string) const { return mayContain(string.impl(
)->hash()); } | 65 bool mayContain(const String& string) const { return mayContain(string.impl(
)->hash()); } |
66 | 66 |
67 #if !ASSERT_DISABLED | 67 #if ASSERT_ENABLED |
68 // Slow. | 68 // Slow. |
69 bool likelyEmpty() const; | 69 bool likelyEmpty() const; |
70 bool isClear() const; | 70 bool isClear() const; |
71 #endif | 71 #endif |
72 | 72 |
73 private: | 73 private: |
74 uint8_t& firstSlot(unsigned hash) { return m_table[hash & keyMask]; } | 74 uint8_t& firstSlot(unsigned hash) { return m_table[hash & keyMask]; } |
75 uint8_t& secondSlot(unsigned hash) { return m_table[(hash >> 16) & keyMask];
} | 75 uint8_t& secondSlot(unsigned hash) { return m_table[(hash >> 16) & keyMask];
} |
76 const uint8_t& firstSlot(unsigned hash) const { return m_table[hash & keyMas
k]; } | 76 const uint8_t& firstSlot(unsigned hash) const { return m_table[hash & keyMas
k]; } |
77 const uint8_t& secondSlot(unsigned hash) const { return m_table[(hash >> 16)
& keyMask]; } | 77 const uint8_t& secondSlot(unsigned hash) const { return m_table[(hash >> 16)
& keyMask]; } |
(...skipping 25 matching lines...) Expand all Loading... |
103 if (LIKELY(second < maximumCount())) | 103 if (LIKELY(second < maximumCount())) |
104 --second; | 104 --second; |
105 } | 105 } |
106 | 106 |
107 template <unsigned keyBits> | 107 template <unsigned keyBits> |
108 inline void BloomFilter<keyBits>::clear() | 108 inline void BloomFilter<keyBits>::clear() |
109 { | 109 { |
110 memset(m_table, 0, tableSize); | 110 memset(m_table, 0, tableSize); |
111 } | 111 } |
112 | 112 |
113 #if !ASSERT_DISABLED | 113 #if ASSERT_ENABLED |
114 template <unsigned keyBits> | 114 template <unsigned keyBits> |
115 bool BloomFilter<keyBits>::likelyEmpty() const | 115 bool BloomFilter<keyBits>::likelyEmpty() const |
116 { | 116 { |
117 for (size_t n = 0; n < tableSize; ++n) { | 117 for (size_t n = 0; n < tableSize; ++n) { |
118 if (m_table[n] && m_table[n] != maximumCount()) | 118 if (m_table[n] && m_table[n] != maximumCount()) |
119 return false; | 119 return false; |
120 } | 120 } |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 template <unsigned keyBits> | 124 template <unsigned keyBits> |
125 bool BloomFilter<keyBits>::isClear() const | 125 bool BloomFilter<keyBits>::isClear() const |
126 { | 126 { |
127 for (size_t n = 0; n < tableSize; ++n) { | 127 for (size_t n = 0; n < tableSize; ++n) { |
128 if (m_table[n]) | 128 if (m_table[n]) |
129 return false; | 129 return false; |
130 } | 130 } |
131 return true; | 131 return true; |
132 } | 132 } |
133 #endif | 133 #endif |
134 | 134 |
135 } | 135 } |
136 | 136 |
137 using WTF::BloomFilter; | 137 using WTF::BloomFilter; |
138 | 138 |
139 #endif | 139 #endif |
OLD | NEW |