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

Side by Side Diff: Source/wtf/HashSet.h

Issue 252633005: Enable WTF::HashSet<OwnPtr<> > (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed implicit conversion in PtrHash<RefPtr>::equal() Created 6 years, 7 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 unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 34
35 template< 35 template<
36 typename ValueArg, 36 typename ValueArg,
37 typename HashArg = typename DefaultHash<ValueArg>::Hash, 37 typename HashArg = typename DefaultHash<ValueArg>::Hash,
38 typename TraitsArg = HashTraits<ValueArg>, 38 typename TraitsArg = HashTraits<ValueArg>,
39 typename Allocator = DefaultAllocator> class HashSet { 39 typename Allocator = DefaultAllocator> class HashSet {
40 WTF_USE_ALLOCATOR(HashSet); 40 WTF_USE_ALLOCATOR(HashSet);
41 private: 41 private:
42 typedef HashArg HashFunctions; 42 typedef HashArg HashFunctions;
43 typedef TraitsArg ValueTraits; 43 typedef TraitsArg ValueTraits;
44 typedef const typename ValueTraits::PeekInType& ValuePeekInType; 44 typedef typename ValueTraits::PeekInType ValuePeekInType;
45 typedef typename ValueTraits::PassInType ValuePassInType;
45 46
46 public: 47 public:
47 typedef typename ValueTraits::TraitType ValueType; 48 typedef typename ValueTraits::TraitType ValueType;
48 49
49 private: 50 private:
50 typedef HashTable<ValueType, ValueType, IdentityExtractor, 51 typedef HashTable<ValueType, ValueType, IdentityExtractor,
51 HashFunctions, ValueTraits, ValueTraits, Allocator> HashTableType; 52 HashFunctions, ValueTraits, ValueTraits, Allocator> HashTableType;
52 53
53 public: 54 public:
54 typedef HashTableConstIteratorAdapter<HashTableType, ValueTraits> iterat or; 55 typedef HashTableConstIteratorAdapter<HashTableType, ValueTraits> iterat or;
(...skipping 24 matching lines...) Expand all
79 // An alternate version of find() that finds the object by hashing and c omparing 80 // An alternate version of find() that finds the object by hashing and c omparing
80 // with some other type, to avoid the cost of type conversion. HashTrans lator 81 // with some other type, to avoid the cost of type conversion. HashTrans lator
81 // must have the following function members: 82 // must have the following function members:
82 // static unsigned hash(const T&); 83 // static unsigned hash(const T&);
83 // static bool equal(const ValueType&, const T&); 84 // static bool equal(const ValueType&, const T&);
84 template<typename HashTranslator, typename T> iterator find(const T&) co nst; 85 template<typename HashTranslator, typename T> iterator find(const T&) co nst;
85 template<typename HashTranslator, typename T> bool contains(const T&) co nst; 86 template<typename HashTranslator, typename T> bool contains(const T&) co nst;
86 87
87 // The return value is a pair of an iterator to the new value's location , 88 // The return value is a pair of an iterator to the new value's location ,
88 // and a bool that is true if an new entry was added. 89 // and a bool that is true if an new entry was added.
89 AddResult add(ValuePeekInType); 90 AddResult add(ValuePassInType);
90 91
91 // An alternate version of add() that finds the object by hashing and co mparing 92 // An alternate version of add() that finds the object by hashing and co mparing
92 // with some other type, to avoid the cost of type conversion if the obj ect is already 93 // with some other type, to avoid the cost of type conversion if the obj ect is already
93 // in the table. HashTranslator must have the following function members : 94 // in the table. HashTranslator must have the following function members :
94 // static unsigned hash(const T&); 95 // static unsigned hash(const T&);
95 // static bool equal(const ValueType&, const T&); 96 // static bool equal(const ValueType&, const T&);
96 // static translate(ValueType&, const T&, unsigned hashCode); 97 // static translate(ValueType&, const T&, unsigned hashCode);
97 template<typename HashTranslator, typename T> AddResult add(const T&); 98 template<typename HashTranslator, typename T> AddResult add(const T&);
98 99
99 void remove(ValuePeekInType); 100 void remove(ValuePeekInType);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 182 }
182 183
183 template<typename Value, typename HashFunctions, typename Traits, typename A llocator> 184 template<typename Value, typename HashFunctions, typename Traits, typename A llocator>
184 template<typename HashTranslator, typename T> 185 template<typename HashTranslator, typename T>
185 inline bool HashSet<Value, HashFunctions, Traits, Allocator>::contains(const T& value) const 186 inline bool HashSet<Value, HashFunctions, Traits, Allocator>::contains(const T& value) const
186 { 187 {
187 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator> >(value); 188 return m_impl.template contains<HashSetTranslatorAdapter<HashTranslator> >(value);
188 } 189 }
189 190
190 template<typename T, typename U, typename V, typename W> 191 template<typename T, typename U, typename V, typename W>
191 inline typename HashSet<T, U, V, W>::AddResult HashSet<T, U, V, W>::add(Valu ePeekInType value) 192 inline typename HashSet<T, U, V, W>::AddResult HashSet<T, U, V, W>::add(Valu ePassInType value)
192 { 193 {
193 return m_impl.add(value); 194 return m_impl.add(value);
194 } 195 }
195 196
196 template<typename Value, typename HashFunctions, typename Traits, typename A llocator> 197 template<typename Value, typename HashFunctions, typename Traits, typename A llocator>
197 template<typename HashTranslator, typename T> 198 template<typename HashTranslator, typename T>
198 inline typename HashSet<Value, HashFunctions, Traits, Allocator>::AddResult 199 inline typename HashSet<Value, HashFunctions, Traits, Allocator>::AddResult
199 HashSet<Value, HashFunctions, Traits, Allocator>::add(const T& value) 200 HashSet<Value, HashFunctions, Traits, Allocator>::add(const T& value)
200 { 201 {
201 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashT ranslator> >(value, value); 202 return m_impl.template addPassingHashCode<HashSetTranslatorAdapter<HashT ranslator> >(value, value);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 238 }
238 239
239 template<typename ValueType, typename HashTableType> 240 template<typename ValueType, typename HashTableType>
240 void deleteAllValues(HashTableType& collection) 241 void deleteAllValues(HashTableType& collection)
241 { 242 {
242 typedef typename HashTableType::const_iterator iterator; 243 typedef typename HashTableType::const_iterator iterator;
243 iterator end = collection.end(); 244 iterator end = collection.end();
244 for (iterator it = collection.begin(); it != end; ++it) 245 for (iterator it = collection.begin(); it != end; ++it)
245 delete *it; 246 delete *it;
246 } 247 }
247 248 // Deprecated, HashSet<OwnPtr<>> to be used instead.
248 template<typename T, typename U, typename V, typename W> 249 template<typename T, typename U, typename V, typename W>
249 inline void deleteAllValues(const HashSet<T, U, V, W>& collection) 250 inline void deleteAllValues(const HashSet<T, U, V, W>& collection)
250 { 251 {
251 deleteAllValues<typename HashSet<T, U, V, W>::ValueType>(collection.m_im pl); 252 deleteAllValues<typename HashSet<T, U, V, W>::ValueType>(collection.m_im pl);
252 } 253 }
253 254
254 template<typename C, typename W> 255 template<typename C, typename W>
255 inline void copyToVector(const C& collection, W& vector) 256 inline void copyToVector(const C& collection, W& vector)
256 { 257 {
257 typedef typename C::const_iterator iterator; 258 typedef typename C::const_iterator iterator;
258 259
259 vector.resize(collection.size()); 260 vector.resize(collection.size());
260 261
261 iterator it = collection.begin(); 262 iterator it = collection.begin();
262 iterator end = collection.end(); 263 iterator end = collection.end();
263 for (unsigned i = 0; it != end; ++it, ++i) 264 for (unsigned i = 0; it != end; ++it, ++i)
264 vector[i] = *it; 265 vector[i] = *it;
265 } 266 }
266 267
267 } // namespace WTF 268 } // namespace WTF
268 269
269 using WTF::HashSet; 270 using WTF::HashSet;
270 271
271 #endif /* WTF_HashSet_h */ 272 #endif /* WTF_HashSet_h */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698