Changeset 223266 in webkit
- Timestamp:
- Oct 12, 2017, 5:39:55 PM (8 years ago)
- Location:
- trunk/Source/WTF
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r223258 r223266 1 2017-10-12 Alex Christensen <achristensen@webkit.org> 2 3 Add Expected, HashMap, HashSet, and SHA1 to wtf/Forward.h 4 https://bugs.webkit.org/show_bug.cgi?id=178243 5 6 Reviewed by Tim Horton. 7 8 * wtf/Forward.h: 9 * wtf/HashMap.h: 10 Move default parameters to Forward.h like we did with Vector. 11 * wtf/HashSet.h: 12 Also fix indentation. 13 1 14 2017-10-12 Alex Christensen <achristensen@webkit.org> 2 15 -
trunk/Source/WTF/wtf/Forward.h
r223258 r223266 29 29 namespace WTF { 30 30 31 class AtomicString; 32 class AtomicStringImpl; 33 class BinarySemaphore; 34 class CString; 35 class CrashOnOverflow; 36 class FunctionDispatcher; 37 class OrdinalNumber; 38 class PrintStream; 39 class SHA1; 40 class String; 41 class StringBuilder; 42 class StringImpl; 43 class StringView; 44 class TextPosition; 45 31 46 struct FastMalloc; 32 class CrashOnOverflow;33 47 34 48 template<typename> class CompletionHandler; … … 45 59 46 60 template<typename...> class Variant; 47 template<typename, size_t inlineCapacity = 0, typename OverflowHandler = CrashOnOverflow, size_t minCapacity = 16, typename Malloc = FastMalloc> class Vector; 48 template<typename Value, typename HashFunctions = typename DefaultHash<Value>::Hash, typename Traits = HashTraits<Value>> class HashCountedSet; 49 50 class AtomicString; 51 class AtomicStringImpl; 52 class BinarySemaphore; 53 class CString; 54 class FunctionDispatcher; 55 class OrdinalNumber; 56 class PrintStream; 57 class String; 58 class StringBuilder; 59 class StringImpl; 60 class StringView; 61 class TextPosition; 61 template<class, class> class Expected; 62 template<typename, size_t = 0, typename = CrashOnOverflow, size_t = 16, typename = FastMalloc> class Vector; 63 template<typename Value, typename = typename DefaultHash<Value>::Hash, typename = HashTraits<Value>> class HashCountedSet; 64 template<typename KeyArg, typename MappedArg, typename = typename DefaultHash<KeyArg>::Hash, typename = HashTraits<KeyArg>, typename = HashTraits<MappedArg>> class HashMap; 65 template<typename ValueArg, typename = typename DefaultHash<ValueArg>::Hash, typename = HashTraits<ValueArg>> class HashSet; 62 66 63 67 } … … 68 72 using WTF::CompletionHandler; 69 73 using WTF::CString; 74 using WTF::Expected; 70 75 using WTF::Function; 71 76 using WTF::FunctionDispatcher; 72 77 using WTF::HashCountedSet; 78 using WTF::HashMap; 79 using WTF::HashSet; 73 80 using WTF::LazyNeverDestroyed; 74 81 using WTF::NeverDestroyed; … … 78 85 using WTF::Ref; 79 86 using WTF::RefPtr; 87 using WTF::SHA1; 80 88 using WTF::String; 81 89 using WTF::StringBuffer; -
trunk/Source/WTF/wtf/HashMap.h
r223238 r223266 23 23 24 24 #include <initializer_list> 25 #include <wtf/Forward.h> 25 26 #include <wtf/HashTable.h> 26 27 #include <wtf/IteratorRange.h> … … 32 33 }; 33 34 34 template<typename KeyArg, typename MappedArg, typename HashArg = typename DefaultHash<KeyArg>::Hash, 35 typename KeyTraitsArg = HashTraits<KeyArg>, typename MappedTraitsArg = HashTraits<MappedArg>> 35 template<typename KeyArg, typename MappedArg, typename HashArg, typename KeyTraitsArg, typename MappedTraitsArg> 36 36 class HashMap final { 37 37 WTF_MAKE_FAST_ALLOCATED; -
trunk/Source/WTF/wtf/HashSet.h
r223238 r223266 23 23 24 24 #include <initializer_list> 25 #include <wtf/Forward.h> 25 26 #include <wtf/GetPtr.h> 26 27 #include <wtf/HashTable.h> … … 28 29 namespace WTF { 29 30 30 struct IdentityExtractor; 31 struct IdentityExtractor; 32 33 template<typename ValueArg, typename HashArg, typename TraitsArg> 34 class HashSet final { 35 WTF_MAKE_FAST_ALLOCATED; 36 private: 37 typedef HashArg HashFunctions; 38 typedef TraitsArg ValueTraits; 39 typedef typename ValueTraits::TakeType TakeType; 40 41 public: 42 typedef typename ValueTraits::TraitType ValueType; 43 44 private: 45 typedef HashTable<ValueType, ValueType, IdentityExtractor, 46 HashFunctions, ValueTraits, ValueTraits> HashTableType; 47 48 public: 49 typedef HashTableConstIteratorAdapter<HashTableType, ValueType> iterator; 50 typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator; 51 typedef typename HashTableType::AddResult AddResult; 52 53 HashSet() 54 { 55 } 56 57 HashSet(std::initializer_list<ValueArg> initializerList) 58 { 59 for (const auto& value : initializerList) 60 add(value); 61 } 62 63 void swap(HashSet&); 64 65 unsigned size() const; 66 unsigned capacity() const; 67 bool isEmpty() const; 68 69 iterator begin() const; 70 iterator end() const; 71 72 iterator find(const ValueType&) const; 73 bool contains(const ValueType&) const; 74 75 // An alternate version of find() that finds the object by hashing and comparing 76 // with some other type, to avoid the cost of type conversion. HashTranslator 77 // must have the following function members: 78 // static unsigned hash(const T&); 79 // static bool equal(const ValueType&, const T&); 80 template<typename HashTranslator, typename T> iterator find(const T&) const; 81 template<typename HashTranslator, typename T> bool contains(const T&) const; 82 83 // The return value includes both an iterator to the added value's location, 84 // and an isNewEntry bool that indicates if it is a new or existing entry in the set. 85 AddResult add(const ValueType&); 86 AddResult add(ValueType&&); 87 void add(std::initializer_list<std::reference_wrapper<const ValueType>>); 88 89 void addVoid(const ValueType&); 90 void addVoid(ValueType&&); 91 92 // An alternate version of add() that finds the object by hashing and comparing 93 // with some other type, to avoid the cost of type conversion if the object is already 94 // in the table. HashTranslator must have the following function members: 95 // static unsigned hash(const T&); 96 // static bool equal(const ValueType&, const T&); 97 // static translate(ValueType&, const T&, unsigned hashCode); 98 template<typename HashTranslator, typename T> AddResult add(const T&); 31 99 32 template<typename Value, typename HashFunctions, typename Traits> class HashSet; 33 34 template<typename ValueArg, typename HashArg = typename DefaultHash<ValueArg>::Hash, 35 typename TraitsArg = HashTraits<ValueArg>> class HashSet final { 36 WTF_MAKE_FAST_ALLOCATED; 37 private: 38 typedef HashArg HashFunctions; 39 typedef TraitsArg ValueTraits; 40 typedef typename ValueTraits::TakeType TakeType; 41 42 public: 43 typedef typename ValueTraits::TraitType ValueType; 44 45 private: 46 typedef HashTable<ValueType, ValueType, IdentityExtractor, 47 HashFunctions, ValueTraits, ValueTraits> HashTableType; 48 49 public: 50 typedef HashTableConstIteratorAdapter<HashTableType, ValueType> iterator; 51 typedef HashTableConstIteratorAdapter<HashTableType, ValueType> const_iterator; 52 typedef typename HashTableType::AddResult AddResult; 53 54 HashSet() 55 { 56 } 57 58 HashSet(std::initializer_list<ValueArg> initializerList) 59 { 60 for (const auto& value : initializerList) 61 add(value); 62 } 63 64 void swap(HashSet&); 65 66 unsigned size() const; 67 unsigned capacity() const; 68 bool isEmpty() const; 69 70 iterator begin() const; 71 iterator end() const; 72 73 iterator find(const ValueType&) const; 74 bool contains(const ValueType&) const; 75 76 // An alternate version of find() that finds the object by hashing and comparing 77 // with some other type, to avoid the cost of type conversion. HashTranslator 78 // must have the following function members: 79 // static unsigned hash(const T&); 80 // static bool equal(const ValueType&, const T&); 81 template<typename HashTranslator, typename T> iterator find(const T&) const; 82 template<typename HashTranslator, typename T> bool contains(const T&) const; 83 84 // The return value includes both an iterator to the added value's location, 85 // and an isNewEntry bool that indicates if it is a new or existing entry in the set. 86 AddResult add(const ValueType&); 87 AddResult add(ValueType&&); 88 void add(std::initializer_list<std::reference_wrapper<const ValueType>>); 89 90 void addVoid(const ValueType&); 91 void addVoid(ValueType&&); 92 93 // An alternate version of add() that finds the object by hashing and comparing 94 // with some other type, to avoid the cost of type conversion if the object is already 95 // in the table. HashTranslator must have the following function members: 96 // static unsigned hash(const T&); 97 // static bool equal(const ValueType&, const T&); 98 // static translate(ValueType&, const T&, unsigned hashCode); 99 template<typename HashTranslator, typename T> AddResult add(const T&); 100 101 // Attempts to add a list of things to the set. Returns true if any of 102 // them are new to the set. Returns false if the set is unchanged. 103 template<typename IteratorType> 104 bool add(IteratorType begin, IteratorType end); 105 106 bool remove(const ValueType&); 107 bool remove(iterator); 108 template<typename Functor> 109 void removeIf(const Functor&); 110 void clear(); 111 112 TakeType take(const ValueType&); 113 TakeType take(iterator); 114 TakeType takeAny(); 115 116 // Overloads for smart pointer values that take the raw pointer type as the parameter. 117 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type find(typename GetPtrHelper<V>::PtrType) const; 118 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type contains(typename GetPtrHelper<V>::PtrType) const; 119 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type remove(typename GetPtrHelper<V>::PtrType); 120 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, TakeType>::type take(typename GetPtrHelper<V>::PtrType); 121 122 static bool isValidValue(const ValueType&); 123 124 template<typename OtherCollection> 125 bool operator==(const OtherCollection&) const; 126 127 template<typename OtherCollection> 128 bool operator!=(const OtherCollection&) const; 129 130 private: 131 HashTableType m_impl; 132 }; 133 134 struct IdentityExtractor { 135 template<typename T> static const T& extract(const T& t) { return t; } 136 }; 137 138 template<typename ValueTraits, typename HashFunctions> 139 struct HashSetTranslator { 140 template<typename T> static unsigned hash(const T& key) { return HashFunctions::hash(key); } 141 template<typename T, typename U> static bool equal(const T& a, const U& b) { return HashFunctions::equal(a, b); } 142 template<typename T, typename U, typename V> static void translate(T& location, U&&, V&& value) 143 { 144 ValueTraits::assignToEmpty(location, std::forward<V>(value)); 145 } 146 }; 147 148 template<typename Translator> 149 struct HashSetTranslatorAdapter { 150 template<typename T> static unsigned hash(const T& key) { return Translator::hash(key); } 151 template<typename T, typename U> static bool equal(const T& a, const U& b) { return Translator::equal(a, b); } 152 template<typename T, typename U> static void translate(T& location, const U& key, const U&, unsigned hashCode) 153 { 154 Translator::translate(location, key, hashCode); 155 } 156 }; 157 158 template<typename T, typename U, typename V> 159 inline void HashSet<T, U, V>::swap(HashSet& other) 100 // Attempts to add a list of things to the set. Returns true if any of 101 // them are new to the set. Returns false if the set is unchanged. 102 template<typename IteratorType> 103 bool add(IteratorType begin, IteratorType end); 104 105 bool remove(const ValueType&); 106 bool remove(iterator); 107 template<typename Functor> 108 void removeIf(const Functor&); 109 void clear(); 110 111 TakeType take(const ValueType&); 112 TakeType take(iterator); 113 TakeType takeAny(); 114 115 // Overloads for smart pointer values that take the raw pointer type as the parameter. 116 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type find(typename GetPtrHelper<V>::PtrType) const; 117 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type contains(typename GetPtrHelper<V>::PtrType) const; 118 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, bool>::type remove(typename GetPtrHelper<V>::PtrType); 119 template<typename V = ValueType> typename std::enable_if<IsSmartPtr<V>::value, TakeType>::type take(typename GetPtrHelper<V>::PtrType); 120 121 static bool isValidValue(const ValueType&); 122 123 template<typename OtherCollection> 124 bool operator==(const OtherCollection&) const; 125 126 template<typename OtherCollection> 127 bool operator!=(const OtherCollection&) const; 128 129 private: 130 HashTableType m_impl; 131 }; 132 133 struct IdentityExtractor { 134 template<typename T> static const T& extract(const T& t) { return t; } 135 }; 136 137 template<typename ValueTraits, typename HashFunctions> 138 struct HashSetTranslator { 139 template<typename T> static unsigned hash(const T& key) { return HashFunctions::hash(key); } 140 template<typename T, typename U> static bool equal(const T& a, const U& b) { return HashFunctions::equal(a, b); } 141 template<typename T, typename U, typename V> static void translate(T& location, U&&, V&& value) 142 { 143 ValueTraits::assignToEmpty(location, std::forward<V>(value)); 144 } 145 }; 146 147 template<typename Translator> 148 struct HashSetTranslatorAdapter { 149 template<typename T> static unsigned hash(const T& key) { return Translator::hash(key); } 150 template<typename T, typename U> static bool equal(const T& a, const U& b) { return Translator::equal(a, b); } 151 template<typename T, typename U> static void translate(T& location, const U& key, const U&, unsigned hashCode) 160 152 { 161 m_impl.swap(other.m_impl); 162 } 163 164 template<typename T, typename U, typename V> 165 inline unsigned HashSet<T, U, V>::size() const 166 { 167 return m_impl.size(); 168 } 169 170 template<typename T, typename U, typename V> 171 inline unsigned HashSet<T, U, V>::capacity() const 172 { 173 return m_impl.capacity(); 174 } 175 176 template<typename T, typename U, typename V> 177 inline bool HashSet<T, U, V>::isEmpty() const 178 { 179 return m_impl.isEmpty(); 180 } 181 182 template<typename T, typename U, typename V> 183 inline auto HashSet<T, U, V>::begin() const -> iterator 184 { 185 return m_impl.begin(); 186 } 187 188 template<typename T, typename U, typename V> 189 inline auto HashSet<T, U, V>::end() const -> iterator 190 { 191 return m_impl.end(); 192 } 193 194 template<typename T, typename U, typename V> 195 inline auto HashSet<T, U, V>::find(const ValueType& value) const -> iterator 196 { 197 return m_impl.find(value); 198 } 199 200 template<typename T, typename U, typename V> 201 inline bool HashSet<T, U, V>::contains(const ValueType& value) const 202 { 203 return m_impl.contains(value); 204 } 205 206 template<typename Value, typename HashFunctions, typename Traits> 207 template<typename HashTranslator, typename T> 208 inline auto HashSet<Value, HashFunctions, Traits>::find(const T& value) const -> iterator 209 { 210 return m_impl.template find<HashSetTranslatorAdapter<HashTranslator>>(value); 211 } 212 213 template<typename Value, typename HashFunctions, typename Traits> 214 template<typename HashTranslator, typename T> 215 inline bool HashSet<Value, HashFunctions, Traits>::contains(const T& value) const 216 { 217 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>>(value); 218 } 219 220 template<typename T, typename U, typename V> 221 inline auto HashSet<T, U, V>::add(const ValueType& value) -> AddResult 222 { 223 return m_impl.add(value); 224 } 225 226 template<typename T, typename U, typename V> 227 inline auto HashSet<T, U, V>::add(ValueType&& value) -> AddResult 228 { 229 return m_impl.add(WTFMove(value)); 230 } 231 232 template<typename T, typename U, typename V> 233 inline void HashSet<T, U, V>::addVoid(const ValueType& value) 234 { 235 m_impl.add(value); 236 } 237 238 template<typename T, typename U, typename V> 239 inline void HashSet<T, U, V>::addVoid(ValueType&& value) 240 { 241 m_impl.add(WTFMove(value)); 242 } 243 244 template<typename Value, typename HashFunctions, typename Traits> 245 template<typename HashTranslator, typename T> 246 inline auto HashSet<Value, HashFunctions, Traits>::add(const T& value) -> AddResult 247 { 248 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashTranslator>>(value, value); 249 } 250 251 template<typename T, typename U, typename V> 252 template<typename IteratorType> 253 inline bool HashSet<T, U, V>::add(IteratorType begin, IteratorType end) 254 { 255 bool changed = false; 256 for (IteratorType iter = begin; iter != end; ++iter) 257 changed |= add(*iter).isNewEntry; 258 return changed; 259 } 260 261 template<typename T, typename U, typename V> 262 inline bool HashSet<T, U, V>::remove(iterator it) 263 { 264 if (it.m_impl == m_impl.end()) 153 Translator::translate(location, key, hashCode); 154 } 155 }; 156 157 template<typename T, typename U, typename V> 158 inline void HashSet<T, U, V>::swap(HashSet& other) 159 { 160 m_impl.swap(other.m_impl); 161 } 162 163 template<typename T, typename U, typename V> 164 inline unsigned HashSet<T, U, V>::size() const 165 { 166 return m_impl.size(); 167 } 168 169 template<typename T, typename U, typename V> 170 inline unsigned HashSet<T, U, V>::capacity() const 171 { 172 return m_impl.capacity(); 173 } 174 175 template<typename T, typename U, typename V> 176 inline bool HashSet<T, U, V>::isEmpty() const 177 { 178 return m_impl.isEmpty(); 179 } 180 181 template<typename T, typename U, typename V> 182 inline auto HashSet<T, U, V>::begin() const -> iterator 183 { 184 return m_impl.begin(); 185 } 186 187 template<typename T, typename U, typename V> 188 inline auto HashSet<T, U, V>::end() const -> iterator 189 { 190 return m_impl.end(); 191 } 192 193 template<typename T, typename U, typename V> 194 inline auto HashSet<T, U, V>::find(const ValueType& value) const -> iterator 195 { 196 return m_impl.find(value); 197 } 198 199 template<typename T, typename U, typename V> 200 inline bool HashSet<T, U, V>::contains(const ValueType& value) const 201 { 202 return m_impl.contains(value); 203 } 204 205 template<typename Value, typename HashFunctions, typename Traits> 206 template<typename HashTranslator, typename T> 207 inline auto HashSet<Value, HashFunctions, Traits>::find(const T& value) const -> iterator 208 { 209 return m_impl.template find<HashSetTranslatorAdapter<HashTranslator>>(value); 210 } 211 212 template<typename Value, typename HashFunctions, typename Traits> 213 template<typename HashTranslator, typename T> 214 inline bool HashSet<Value, HashFunctions, Traits>::contains(const T& value) const 215 { 216 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>>(value); 217 } 218 219 template<typename T, typename U, typename V> 220 inline auto HashSet<T, U, V>::add(const ValueType& value) -> AddResult 221 { 222 return m_impl.add(value); 223 } 224 225 template<typename T, typename U, typename V> 226 inline auto HashSet<T, U, V>::add(ValueType&& value) -> AddResult 227 { 228 return m_impl.add(WTFMove(value)); 229 } 230 231 template<typename T, typename U, typename V> 232 inline void HashSet<T, U, V>::addVoid(const ValueType& value) 233 { 234 m_impl.add(value); 235 } 236 237 template<typename T, typename U, typename V> 238 inline void HashSet<T, U, V>::addVoid(ValueType&& value) 239 { 240 m_impl.add(WTFMove(value)); 241 } 242 243 template<typename Value, typename HashFunctions, typename Traits> 244 template<typename HashTranslator, typename T> 245 inline auto HashSet<Value, HashFunctions, Traits>::add(const T& value) -> AddResult 246 { 247 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashTranslator>>(value, value); 248 } 249 250 template<typename T, typename U, typename V> 251 template<typename IteratorType> 252 inline bool HashSet<T, U, V>::add(IteratorType begin, IteratorType end) 253 { 254 bool changed = false; 255 for (IteratorType iter = begin; iter != end; ++iter) 256 changed |= add(*iter).isNewEntry; 257 return changed; 258 } 259 260 template<typename T, typename U, typename V> 261 inline bool HashSet<T, U, V>::remove(iterator it) 262 { 263 if (it.m_impl == m_impl.end()) 264 return false; 265 m_impl.internalCheckTableConsistency(); 266 m_impl.removeWithoutEntryConsistencyCheck(it.m_impl); 267 return true; 268 } 269 270 template<typename T, typename U, typename V> 271 inline bool HashSet<T, U, V>::remove(const ValueType& value) 272 { 273 return remove(find(value)); 274 } 275 276 template<typename T, typename U, typename V> 277 template<typename Functor> 278 inline void HashSet<T, U, V>::removeIf(const Functor& functor) 279 { 280 m_impl.removeIf(functor); 281 } 282 283 template<typename T, typename U, typename V> 284 inline void HashSet<T, U, V>::clear() 285 { 286 m_impl.clear(); 287 } 288 289 template<typename T, typename U, typename V> 290 inline auto HashSet<T, U, V>::take(iterator it) -> TakeType 291 { 292 if (it == end()) 293 return ValueTraits::take(ValueTraits::emptyValue()); 294 295 auto result = ValueTraits::take(WTFMove(const_cast<ValueType&>(*it))); 296 remove(it); 297 return result; 298 } 299 300 template<typename T, typename U, typename V> 301 inline auto HashSet<T, U, V>::take(const ValueType& value) -> TakeType 302 { 303 return take(find(value)); 304 } 305 306 template<typename T, typename U, typename V> 307 inline auto HashSet<T, U, V>::takeAny() -> TakeType 308 { 309 return take(begin()); 310 } 311 312 template<typename Value, typename HashFunctions, typename Traits> 313 template<typename V> 314 inline auto HashSet<Value, HashFunctions, Traits>::find(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type 315 { 316 return m_impl.template find<HashSetTranslator<Traits, HashFunctions>>(value); 317 } 318 319 template<typename Value, typename HashFunctions, typename Traits> 320 template<typename V> 321 inline auto HashSet<Value, HashFunctions, Traits>::contains(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type 322 { 323 return m_impl.template contains<HashSetTranslator<Traits, HashFunctions>>(value); 324 } 325 326 template<typename Value, typename HashFunctions, typename Traits> 327 template<typename V> 328 inline auto HashSet<Value, HashFunctions, Traits>::remove(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type 329 { 330 return remove(find(value)); 331 } 332 333 template<typename Value, typename HashFunctions, typename Traits> 334 template<typename V> 335 inline auto HashSet<Value, HashFunctions, Traits>::take(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, TakeType>::type 336 { 337 return take(find(value)); 338 } 339 340 template<typename T, typename U, typename V> 341 inline bool HashSet<T, U, V>::isValidValue(const ValueType& value) 342 { 343 if (ValueTraits::isDeletedValue(value)) 344 return false; 345 346 if (HashFunctions::safeToCompareToEmptyOrDeleted) { 347 if (value == ValueTraits::emptyValue()) 265 348 return false; 266 m_impl.internalCheckTableConsistency(); 267 m_impl.removeWithoutEntryConsistencyCheck(it.m_impl); 268 return true; 269 } 270 271 template<typename T, typename U, typename V> 272 inline bool HashSet<T, U, V>::remove(const ValueType& value) 273 { 274 return remove(find(value)); 275 } 276 277 template<typename T, typename U, typename V> 278 template<typename Functor> 279 inline void HashSet<T, U, V>::removeIf(const Functor& functor) 280 { 281 m_impl.removeIf(functor); 282 } 283 284 template<typename T, typename U, typename V> 285 inline void HashSet<T, U, V>::clear() 286 { 287 m_impl.clear(); 288 } 289 290 template<typename T, typename U, typename V> 291 inline auto HashSet<T, U, V>::take(iterator it) -> TakeType 292 { 293 if (it == end()) 294 return ValueTraits::take(ValueTraits::emptyValue()); 295 296 auto result = ValueTraits::take(WTFMove(const_cast<ValueType&>(*it))); 297 remove(it); 298 return result; 299 } 300 301 template<typename T, typename U, typename V> 302 inline auto HashSet<T, U, V>::take(const ValueType& value) -> TakeType 303 { 304 return take(find(value)); 305 } 306 307 template<typename T, typename U, typename V> 308 inline auto HashSet<T, U, V>::takeAny() -> TakeType 309 { 310 return take(begin()); 311 } 312 313 template<typename Value, typename HashFunctions, typename Traits> 314 template<typename V> 315 inline auto HashSet<Value, HashFunctions, Traits>::find(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, iterator>::type 316 { 317 return m_impl.template find<HashSetTranslator<Traits, HashFunctions>>(value); 318 } 319 320 template<typename Value, typename HashFunctions, typename Traits> 321 template<typename V> 322 inline auto HashSet<Value, HashFunctions, Traits>::contains(typename GetPtrHelper<V>::PtrType value) const -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type 323 { 324 return m_impl.template contains<HashSetTranslator<Traits, HashFunctions>>(value); 325 } 326 327 template<typename Value, typename HashFunctions, typename Traits> 328 template<typename V> 329 inline auto HashSet<Value, HashFunctions, Traits>::remove(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, bool>::type 330 { 331 return remove(find(value)); 332 } 333 334 template<typename Value, typename HashFunctions, typename Traits> 335 template<typename V> 336 inline auto HashSet<Value, HashFunctions, Traits>::take(typename GetPtrHelper<V>::PtrType value) -> typename std::enable_if<IsSmartPtr<V>::value, TakeType>::type 337 { 338 return take(find(value)); 339 } 340 341 template<typename T, typename U, typename V> 342 inline bool HashSet<T, U, V>::isValidValue(const ValueType& value) 343 { 344 if (ValueTraits::isDeletedValue(value)) 349 } else { 350 if (isHashTraitsEmptyValue<ValueTraits>(value)) 345 351 return false; 346 347 if (HashFunctions::safeToCompareToEmptyOrDeleted) { 348 if (value == ValueTraits::emptyValue()) 349 return false; 350 } else { 351 if (isHashTraitsEmptyValue<ValueTraits>(value)) 352 return false; 353 } 354 355 return true; 356 } 357 358 template<typename T, typename U, typename V> 359 template<typename OtherCollection> 360 inline bool HashSet<T, U, V>::operator==(const OtherCollection& otherCollection) const 361 { 362 if (size() != otherCollection.size()) 352 } 353 354 return true; 355 } 356 357 template<typename T, typename U, typename V> 358 template<typename OtherCollection> 359 inline bool HashSet<T, U, V>::operator==(const OtherCollection& otherCollection) const 360 { 361 if (size() != otherCollection.size()) 362 return false; 363 for (const auto& other : otherCollection) { 364 if (!contains(other)) 363 365 return false; 364 for (const auto& other : otherCollection) { 365 if (!contains(other)) 366 return false; 367 } 368 return true; 369 } 370 371 template<typename T, typename U, typename V> 372 template<typename OtherCollection> 373 inline bool HashSet<T, U, V>::operator!=(const OtherCollection& otherCollection) const 374 { 375 return !(*this == otherCollection); 376 } 377 378 template<typename T, typename U, typename V> 379 void HashSet<T, U, V>::add(std::initializer_list<std::reference_wrapper<const ValueType>> list) 380 { 381 for (auto& value : list) 382 add(value); 383 } 366 } 367 return true; 368 } 369 370 template<typename T, typename U, typename V> 371 template<typename OtherCollection> 372 inline bool HashSet<T, U, V>::operator!=(const OtherCollection& otherCollection) const 373 { 374 return !(*this == otherCollection); 375 } 376 377 template<typename T, typename U, typename V> 378 void HashSet<T, U, V>::add(std::initializer_list<std::reference_wrapper<const ValueType>> list) 379 { 380 for (auto& value : list) 381 add(value); 382 } 384 383 385 384 } // namespace WTF
Note:
See TracChangeset
for help on using the changeset viewer.