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

Side by Side Diff: Source/wtf/HashMap.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
« no previous file with comments | « Source/web/AssociatedURLLoader.cpp ('k') | Source/wtf/HashSet.h » ('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 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 AddResult set(KeyPeekInType, MappedPassInType); 119 AddResult set(KeyPeekInType, MappedPassInType);
120 120
121 // does nothing if key is already present 121 // does nothing if key is already present
122 // return value is a pair of the iterator to the key location, 122 // return value is a pair of the iterator to the key location,
123 // and a boolean that's true if a new value was actually added 123 // and a boolean that's true if a new value was actually added
124 AddResult add(KeyPeekInType, MappedPassInType); 124 AddResult add(KeyPeekInType, MappedPassInType);
125 125
126 void remove(KeyPeekInType); 126 void remove(KeyPeekInType);
127 void remove(iterator); 127 void remove(iterator);
128 void clear(); 128 void clear();
129 template<typename Collection>
130 void removeAll(const Collection& other);
129 131
130 MappedPassOutType take(KeyPeekInType); // efficient combination of get w ith remove 132 MappedPassOutType take(KeyPeekInType); // efficient combination of get w ith remove
131 133
132 // An alternate version of find() that finds the object by hashing and c omparing 134 // An alternate version of find() that finds the object by hashing and c omparing
133 // with some other type, to avoid the cost of type conversion. HashTrans lator 135 // with some other type, to avoid the cost of type conversion. HashTrans lator
134 // must have the following function members: 136 // must have the following function members:
135 // static unsigned hash(const T&); 137 // static unsigned hash(const T&);
136 // static bool equal(const ValueType&, const T&); 138 // static bool equal(const ValueType&, const T&);
137 template<typename HashTranslator, typename T> iterator find(const T&); 139 template<typename HashTranslator, typename T> iterator find(const T&);
138 template<typename HashTranslator, typename T> const_iterator find(const T&) const; 140 template<typename HashTranslator, typename T> const_iterator find(const T&) const;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 remove(find(key)); 407 remove(find(key));
406 } 408 }
407 409
408 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 410 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
409 inline void HashMap<T, U, V, W, X, Y>::clear() 411 inline void HashMap<T, U, V, W, X, Y>::clear()
410 { 412 {
411 m_impl.clear(); 413 m_impl.clear();
412 } 414 }
413 415
414 template<typename T, typename U, typename V, typename W, typename X, typenam e Y> 416 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
417 template<typename Collection>
418 inline void HashMap<T, U, V, W, X, Y>::removeAll(const Collection& other)
Mikhail 2014/04/25 11:02:26 I'm a bit concerned that this code is repeated at
Erik Corry 2014/04/25 12:00:31 Done.
419 {
420 if (other.isEmpty() || isEmpty())
421 return;
422 typedef typename Collection::const_iterator CollectionIterator;
423 CollectionIterator otherEnd(other.end());
424 for (CollectionIterator it(other.begin()); it != otherEnd; ++it)
425 remove(*it);
426 }
427
428 template<typename T, typename U, typename V, typename W, typename X, typenam e Y>
415 typename HashMap<T, U, V, W, X, Y>::MappedPassOutType 429 typename HashMap<T, U, V, W, X, Y>::MappedPassOutType
416 HashMap<T, U, V, W, X, Y>::take(KeyPeekInType key) 430 HashMap<T, U, V, W, X, Y>::take(KeyPeekInType key)
417 { 431 {
418 iterator it = find(key); 432 iterator it = find(key);
419 if (it == end()) 433 if (it == end())
420 return MappedTraits::passOut(MappedTraits::emptyValue()); 434 return MappedTraits::passOut(MappedTraits::emptyValue());
421 MappedPassOutType result = MappedTraits::passOut(it->value); 435 MappedPassOutType result = MappedTraits::passOut(it->value);
422 remove(it); 436 remove(it);
423 return result; 437 return result;
424 } 438 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 iterator end = collection.end().values(); 521 iterator end = collection.end().values();
508 for (unsigned i = 0; it != end; ++it, ++i) 522 for (unsigned i = 0; it != end; ++it, ++i)
509 vector[i] = *it; 523 vector[i] = *it;
510 } 524 }
511 525
512 } // namespace WTF 526 } // namespace WTF
513 527
514 using WTF::HashMap; 528 using WTF::HashMap;
515 529
516 #endif /* WTF_HashMap_h */ 530 #endif /* WTF_HashMap_h */
OLDNEW
« no previous file with comments | « Source/web/AssociatedURLLoader.cpp ('k') | Source/wtf/HashSet.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698