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

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

Issue 256743005: Add removeAll method to sets and maps and use them (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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
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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // Add the value to the beginning of the collection. If the value was al ready in 149 // Add the value to the beginning of the collection. If the value was al ready in
150 // the list, it is moved to the beginning. 150 // the list, it is moved to the beginning.
151 AddResult prependOrMoveToFirst(ValuePeekInType); 151 AddResult prependOrMoveToFirst(ValuePeekInType);
152 152
153 AddResult insertBefore(ValuePeekInType beforeValue, ValuePeekInType newV alue); 153 AddResult insertBefore(ValuePeekInType beforeValue, ValuePeekInType newV alue);
154 AddResult insertBefore(iterator, ValuePeekInType); 154 AddResult insertBefore(iterator, ValuePeekInType);
155 155
156 void remove(ValuePeekInType); 156 void remove(ValuePeekInType);
157 void remove(iterator); 157 void remove(iterator);
158 void clear(); 158 void clear();
159 template<typename Collection>
160 void removeAll(const Collection& other);
159 161
160 private: 162 private:
161 void unlink(Node*); 163 void unlink(Node*);
162 void unlinkAndDelete(Node*); 164 void unlinkAndDelete(Node*);
163 void appendNode(Node*); 165 void appendNode(Node*);
164 void prependNode(Node*); 166 void prependNode(Node*);
165 void insertNodeBefore(Node* beforeNode, Node* newNode); 167 void insertNodeBefore(Node* beforeNode, Node* newNode);
166 void deleteAllNodes(); 168 void deleteAllNodes();
167 void createAllocatorIfNeeded(); 169 void createAllocatorIfNeeded();
168 170
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 template<typename T, size_t inlineCapacity, typename U> 833 template<typename T, size_t inlineCapacity, typename U>
832 inline void ListHashSet<T, inlineCapacity, U>::clear() 834 inline void ListHashSet<T, inlineCapacity, U>::clear()
833 { 835 {
834 deleteAllNodes(); 836 deleteAllNodes();
835 m_impl.clear(); 837 m_impl.clear();
836 m_head = 0; 838 m_head = 0;
837 m_tail = 0; 839 m_tail = 0;
838 } 840 }
839 841
840 template<typename T, size_t inlineCapacity, typename U> 842 template<typename T, size_t inlineCapacity, typename U>
843 template<typename Collection>
844 inline void ListHashSet<T, inlineCapacity, U>::removeAll(const Collection& o ther)
845 {
846 if (other.isEmpty() || isEmpty())
847 return;
848 typedef typename Collection::const_iterator CollectionIterator;
849 CollectionIterator otherEnd(other.end());
850 for (CollectionIterator it(other.begin()); it != otherEnd; ++it)
851 remove(*it);
852 }
853
854 template<typename T, size_t inlineCapacity, typename U>
841 void ListHashSet<T, inlineCapacity, U>::unlink(Node* node) 855 void ListHashSet<T, inlineCapacity, U>::unlink(Node* node)
842 { 856 {
843 if (!node->m_prev) { 857 if (!node->m_prev) {
844 ASSERT(node == m_head); 858 ASSERT(node == m_head);
845 m_head = node->m_next; 859 m_head = node->m_next;
846 } else { 860 } else {
847 ASSERT(node != m_head); 861 ASSERT(node != m_head);
848 node->m_prev->m_next = node->m_next; 862 node->m_prev->m_next = node->m_next;
849 } 863 }
850 864
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 inline void deleteAllValues(const ListHashSet<T, inlineCapacity, U>& collect ion) 982 inline void deleteAllValues(const ListHashSet<T, inlineCapacity, U>& collect ion)
969 { 983 {
970 deleteAllValues<true, typename ListHashSet<T, inlineCapacity, U>::ValueT ype>(collection.m_impl); 984 deleteAllValues<true, typename ListHashSet<T, inlineCapacity, U>::ValueT ype>(collection.m_impl);
971 } 985 }
972 986
973 } // namespace WTF 987 } // namespace WTF
974 988
975 using WTF::ListHashSet; 989 using WTF::ListHashSet;
976 990
977 #endif /* WTF_ListHashSet_h */ 991 #endif /* WTF_ListHashSet_h */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698