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

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

Issue 223373002: Create HeapLinkedHashSet and LinkedHashSet, ordered heap-friendly hash sets. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix gtest-related compile error on gcc by removing internal typedefs in iterators Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/LinkedHashSet.h ('k') | Source/wtf/ListHashSetTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2011, Benjamin Poulain <ikipou@gmail.com> 3 * Copyright (C) 2011, Benjamin Poulain <ikipou@gmail.com>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 293
294 template<typename HashArg> struct ListHashSetNodeHashFunctions { 294 template<typename HashArg> struct ListHashSetNodeHashFunctions {
295 template<typename T> static unsigned hash(const T& key) { return HashArg ::hash(key->m_value); } 295 template<typename T> static unsigned hash(const T& key) { return HashArg ::hash(key->m_value); }
296 template<typename T> static bool equal(const T& a, const T& b) { return HashArg::equal(a->m_value, b->m_value); } 296 template<typename T> static bool equal(const T& a, const T& b) { return HashArg::equal(a->m_value, b->m_value); }
297 static const bool safeToCompareToEmptyOrDeleted = false; 297 static const bool safeToCompareToEmptyOrDeleted = false;
298 }; 298 };
299 299
300 template<typename ValueArg, size_t inlineCapacity, typename HashArg> class L istHashSetIterator { 300 template<typename ValueArg, size_t inlineCapacity, typename HashArg> class L istHashSetIterator {
301 private: 301 private:
302 typedef ListHashSet<ValueArg, inlineCapacity, HashArg> ListHashSetType; 302 typedef ListHashSet<ValueArg, inlineCapacity, HashArg> ListHashSetType;
303 typedef ListHashSetIterator<ValueArg, inlineCapacity, HashArg> iterator;
304 typedef ListHashSetConstIterator<ValueArg, inlineCapacity, HashArg> cons t_iterator; 303 typedef ListHashSetConstIterator<ValueArg, inlineCapacity, HashArg> cons t_iterator;
305 typedef ListHashSetNode<ValueArg, inlineCapacity> Node; 304 typedef ListHashSetNode<ValueArg, inlineCapacity> Node;
306 typedef ValueArg ValueType; 305 typedef ValueArg ValueType;
307 typedef ValueType& ReferenceType; 306 typedef ValueType& ReferenceType;
308 typedef ValueType* PointerType; 307 typedef ValueType* PointerType;
309 308
310 friend class ListHashSet<ValueArg, inlineCapacity, HashArg>; 309 friend class ListHashSet<ValueArg, inlineCapacity, HashArg>;
311 310
312 ListHashSetIterator(const ListHashSetType* set, Node* position) : m_iter ator(set, position) { } 311 ListHashSetIterator(const ListHashSetType* set, Node* position) : m_iter ator(set, position) { }
313 312
314 public: 313 public:
315 ListHashSetIterator() { } 314 ListHashSetIterator() { }
316 315
317 // default copy, assignment and destructor are OK 316 // default copy, assignment and destructor are OK
318 317
319 PointerType get() const { return const_cast<PointerType>(m_iterator.get( )); } 318 PointerType get() const { return const_cast<PointerType>(m_iterator.get( )); }
320 ReferenceType operator*() const { return *get(); } 319 ReferenceType operator*() const { return *get(); }
321 PointerType operator->() const { return get(); } 320 PointerType operator->() const { return get(); }
322 321
323 iterator& operator++() { ++m_iterator; return *this; } 322 ListHashSetIterator& operator++() { ++m_iterator; return *this; }
324 323
325 // postfix ++ intentionally omitted 324 // postfix ++ intentionally omitted
326 325
327 iterator& operator--() { --m_iterator; return *this; } 326 ListHashSetIterator& operator--() { --m_iterator; return *this; }
328 327
329 // postfix -- intentionally omitted 328 // postfix -- intentionally omitted
330 329
331 // Comparison. 330 // Comparison.
332 bool operator==(const iterator& other) const { return m_iterator == othe r.m_iterator; } 331 bool operator==(const ListHashSetIterator& other) const { return m_itera tor == other.m_iterator; }
333 bool operator!=(const iterator& other) const { return m_iterator != othe r.m_iterator; } 332 bool operator!=(const ListHashSetIterator& other) const { return m_itera tor != other.m_iterator; }
334 333
335 operator const_iterator() const { return m_iterator; } 334 operator const_iterator() const { return m_iterator; }
336 335
337 private: 336 private:
338 Node* node() { return m_iterator.node(); } 337 Node* node() { return m_iterator.node(); }
339 338
340 const_iterator m_iterator; 339 const_iterator m_iterator;
341 }; 340 };
342 341
343 template<typename ValueArg, size_t inlineCapacity, typename HashArg> class L istHashSetConstIterator { 342 template<typename ValueArg, size_t inlineCapacity, typename HashArg> class L istHashSetConstIterator {
344 private: 343 private:
345 typedef ListHashSet<ValueArg, inlineCapacity, HashArg> ListHashSetType; 344 typedef ListHashSet<ValueArg, inlineCapacity, HashArg> ListHashSetType;
346 typedef ListHashSetIterator<ValueArg, inlineCapacity, HashArg> iterator;
347 typedef ListHashSetConstIterator<ValueArg, inlineCapacity, HashArg> cons t_iterator; 345 typedef ListHashSetConstIterator<ValueArg, inlineCapacity, HashArg> cons t_iterator;
348 typedef ListHashSetNode<ValueArg, inlineCapacity> Node; 346 typedef ListHashSetNode<ValueArg, inlineCapacity> Node;
349 typedef ValueArg ValueType; 347 typedef ValueArg ValueType;
350 typedef const ValueType& ReferenceType; 348 typedef const ValueType& ReferenceType;
351 typedef const ValueType* PointerType; 349 typedef const ValueType* PointerType;
352 350
353 friend class ListHashSet<ValueArg, inlineCapacity, HashArg>; 351 friend class ListHashSet<ValueArg, inlineCapacity, HashArg>;
354 friend class ListHashSetIterator<ValueArg, inlineCapacity, HashArg>; 352 friend class ListHashSetIterator<ValueArg, inlineCapacity, HashArg>;
355 353
356 ListHashSetConstIterator(const ListHashSetType* set, Node* position) 354 ListHashSetConstIterator(const ListHashSetType* set, Node* position)
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 inline ListHashSetIterator<T, inlineCapacity, U> ListHashSet<T, inlineCapaci ty, U>::makeIterator(Node* position) 937 inline ListHashSetIterator<T, inlineCapacity, U> ListHashSet<T, inlineCapaci ty, U>::makeIterator(Node* position)
940 { 938 {
941 return ListHashSetIterator<T, inlineCapacity, U>(this, position); 939 return ListHashSetIterator<T, inlineCapacity, U>(this, position);
942 } 940 }
943 941
944 template<typename T, size_t inlineCapacity, typename U> 942 template<typename T, size_t inlineCapacity, typename U>
945 inline ListHashSetConstIterator<T, inlineCapacity, U> ListHashSet<T, inlineC apacity, U>::makeConstIterator(Node* position) const 943 inline ListHashSetConstIterator<T, inlineCapacity, U> ListHashSet<T, inlineC apacity, U>::makeConstIterator(Node* position) const
946 { 944 {
947 return ListHashSetConstIterator<T, inlineCapacity, U>(this, position); 945 return ListHashSetConstIterator<T, inlineCapacity, U>(this, position);
948 } 946 }
947
949 template<bool, typename ValueType, typename HashTableType> 948 template<bool, typename ValueType, typename HashTableType>
950 void deleteAllValues(HashTableType& collection) 949 void deleteAllValues(HashTableType& collection)
951 { 950 {
952 typedef typename HashTableType::const_iterator iterator; 951 typedef typename HashTableType::const_iterator iterator;
953 iterator end = collection.end(); 952 iterator end = collection.end();
954 for (iterator it = collection.begin(); it != end; ++it) 953 for (iterator it = collection.begin(); it != end; ++it)
955 delete (*it)->m_value; 954 delete (*it)->m_value;
956 } 955 }
957 956
957 // Warning: After and while calling this you have a collection with deleted
958 // pointers. Consider using a smart pointer like OwnPtr and calling clear()
959 // instead.
958 template<typename T, size_t inlineCapacity, typename U> 960 template<typename T, size_t inlineCapacity, typename U>
959 inline void deleteAllValues(const ListHashSet<T, inlineCapacity, U>& collect ion) 961 inline void deleteAllValues(const ListHashSet<T, inlineCapacity, U>& collect ion)
960 { 962 {
961 deleteAllValues<true, typename ListHashSet<T, inlineCapacity, U>::ValueT ype>(collection.m_impl); 963 deleteAllValues<true, typename ListHashSet<T, inlineCapacity, U>::ValueT ype>(collection.m_impl);
962 } 964 }
963 965
964 } // namespace WTF 966 } // namespace WTF
965 967
966 using WTF::ListHashSet; 968 using WTF::ListHashSet;
967 969
968 #endif /* WTF_ListHashSet_h */ 970 #endif /* WTF_ListHashSet_h */
OLDNEW
« no previous file with comments | « Source/wtf/LinkedHashSet.h ('k') | Source/wtf/ListHashSetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698