| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // static unsigned hash(const T&); | 99 // static unsigned hash(const T&); |
| 100 // static bool equal(const ValueType&, const T&); | 100 // static bool equal(const ValueType&, const T&); |
| 101 template <typename HashTranslator, typename T> | 101 template <typename HashTranslator, typename T> |
| 102 iterator find(const T&) const; | 102 iterator find(const T&) const; |
| 103 template <typename HashTranslator, typename T> | 103 template <typename HashTranslator, typename T> |
| 104 bool contains(const T&) const; | 104 bool contains(const T&) const; |
| 105 | 105 |
| 106 // The return value is a pair of an iterator to the new value's location, | 106 // The return value is a pair of an iterator to the new value's location, |
| 107 // and a bool that is true if an new entry was added. | 107 // and a bool that is true if an new entry was added. |
| 108 template <typename IncomingValueType> | 108 template <typename IncomingValueType> |
| 109 AddResult insert(IncomingValueType&&); |
| 110 template <typename IncomingValueType> |
| 109 AddResult add(IncomingValueType&&); | 111 AddResult add(IncomingValueType&&); |
| 110 | 112 |
| 111 // An alternate version of add() that finds the object by hashing and | 113 // An alternate version of add() that finds the object by hashing and |
| 112 // comparing with some other type, to avoid the cost of type conversion if | 114 // comparing with some other type, to avoid the cost of type conversion if |
| 113 // the object is already in the table. HashTranslator must have the | 115 // the object is already in the table. HashTranslator must have the |
| 114 // following function members: | 116 // following function members: |
| 115 // static unsigned hash(const T&); | 117 // static unsigned hash(const T&); |
| 116 // static bool equal(const ValueType&, const T&); | 118 // static bool equal(const ValueType&, const T&); |
| 117 // static translate(ValueType&, T&&, unsigned hashCode); | 119 // static translate(ValueType&, T&&, unsigned hashCode); |
| 118 template <typename HashTranslator, typename T> | 120 template <typename HashTranslator, typename T> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 168 |
| 167 template <typename Value, | 169 template <typename Value, |
| 168 typename HashFunctions, | 170 typename HashFunctions, |
| 169 typename Traits, | 171 typename Traits, |
| 170 typename Allocator> | 172 typename Allocator> |
| 171 HashSet<Value, HashFunctions, Traits, Allocator>::HashSet( | 173 HashSet<Value, HashFunctions, Traits, Allocator>::HashSet( |
| 172 std::initializer_list<ValueType> elements) { | 174 std::initializer_list<ValueType> elements) { |
| 173 if (elements.size()) | 175 if (elements.size()) |
| 174 m_impl.reserveCapacityForSize(elements.size()); | 176 m_impl.reserveCapacityForSize(elements.size()); |
| 175 for (const ValueType& element : elements) | 177 for (const ValueType& element : elements) |
| 176 add(element); | 178 insert(element); |
| 177 } | 179 } |
| 178 | 180 |
| 179 template <typename Value, | 181 template <typename Value, |
| 180 typename HashFunctions, | 182 typename HashFunctions, |
| 181 typename Traits, | 183 typename Traits, |
| 182 typename Allocator> | 184 typename Allocator> |
| 183 auto HashSet<Value, HashFunctions, Traits, Allocator>::operator=( | 185 auto HashSet<Value, HashFunctions, Traits, Allocator>::operator=( |
| 184 std::initializer_list<ValueType> elements) -> HashSet& { | 186 std::initializer_list<ValueType> elements) -> HashSet& { |
| 185 *this = HashSet(std::move(elements)); | 187 *this = HashSet(std::move(elements)); |
| 186 return *this; | 188 return *this; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 typename Allocator> | 246 typename Allocator> |
| 245 template <typename HashTranslator, typename T> | 247 template <typename HashTranslator, typename T> |
| 246 inline bool HashSet<Value, HashFunctions, Traits, Allocator>::contains( | 248 inline bool HashSet<Value, HashFunctions, Traits, Allocator>::contains( |
| 247 const T& value) const { | 249 const T& value) const { |
| 248 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>>( | 250 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator>>( |
| 249 value); | 251 value); |
| 250 } | 252 } |
| 251 | 253 |
| 252 template <typename T, typename U, typename V, typename W> | 254 template <typename T, typename U, typename V, typename W> |
| 253 template <typename IncomingValueType> | 255 template <typename IncomingValueType> |
| 256 inline typename HashSet<T, U, V, W>::AddResult HashSet<T, U, V, W>::insert( |
| 257 IncomingValueType&& value) { |
| 258 return m_impl.add(std::forward<IncomingValueType>(value)); |
| 259 } |
| 260 |
| 261 // TODO(pilgrim) remove this method once all references and subclasses |
| 262 // have been migrated to insert() method |
| 263 template <typename T, typename U, typename V, typename W> |
| 264 template <typename IncomingValueType> |
| 254 inline typename HashSet<T, U, V, W>::AddResult HashSet<T, U, V, W>::add( | 265 inline typename HashSet<T, U, V, W>::AddResult HashSet<T, U, V, W>::add( |
| 255 IncomingValueType&& value) { | 266 IncomingValueType&& value) { |
| 256 return m_impl.add(std::forward<IncomingValueType>(value)); | 267 return m_impl.add(std::forward<IncomingValueType>(value)); |
| 257 } | 268 } |
| 258 | 269 |
| 259 template <typename Value, | 270 template <typename Value, |
| 260 typename HashFunctions, | 271 typename HashFunctions, |
| 261 typename Traits, | 272 typename Traits, |
| 262 typename Allocator> | 273 typename Allocator> |
| 263 template <typename HashTranslator, typename T> | 274 template <typename HashTranslator, typename T> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 iterator end = collection.end(); | 331 iterator end = collection.end(); |
| 321 for (unsigned i = 0; it != end; ++it, ++i) | 332 for (unsigned i = 0; it != end; ++it, ++i) |
| 322 vector[i] = *it; | 333 vector[i] = *it; |
| 323 } | 334 } |
| 324 | 335 |
| 325 } // namespace WTF | 336 } // namespace WTF |
| 326 | 337 |
| 327 using WTF::HashSet; | 338 using WTF::HashSet; |
| 328 | 339 |
| 329 #endif // WTF_HashSet_h | 340 #endif // WTF_HashSet_h |
| OLD | NEW |