OLD | NEW |
1 // | 1 // |
2 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 // | 5 // |
6 // STL utility functions. Usually, these replace built-in, but slow(!), | 6 // STL utility functions. Usually, these replace built-in, but slow(!), |
7 // STL functions with more efficient versions. | 7 // STL functions with more efficient versions. |
8 // | 8 // |
9 | 9 |
10 #ifndef CHROME_COMMON_STL_UTIL_INL_H__ | 10 #ifndef CHROME_COMMON_STL_UTIL_INL_H__ |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // because the == operator in the STL can return false when the maps/sets | 189 // because the == operator in the STL can return false when the maps/sets |
190 // contain identical elements. This is because it compares the internal hash | 190 // contain identical elements. This is because it compares the internal hash |
191 // tables which may be different if the order of insertions and deletions | 191 // tables which may be different if the order of insertions and deletions |
192 // differed. | 192 // differed. |
193 | 193 |
194 template <class HashSet> | 194 template <class HashSet> |
195 inline bool | 195 inline bool |
196 HashSetEquality(const HashSet& set_a, | 196 HashSetEquality(const HashSet& set_a, |
197 const HashSet& set_b) { | 197 const HashSet& set_b) { |
198 if (set_a.size() != set_b.size()) return false; | 198 if (set_a.size() != set_b.size()) return false; |
199 for (typename HashSet::const_iterator i = set_a.begin(); i != set_a.end(); ++i
) | 199 for (typename HashSet::const_iterator i = set_a.begin(); |
200 if (set_b.find(*i) == set_b.end()) return false; | 200 i != set_a.end(); |
| 201 ++i) { |
| 202 if (set_b.find(*i) == set_b.end()) |
| 203 return false; |
| 204 } |
201 return true; | 205 return true; |
202 } | 206 } |
203 | 207 |
204 template <class HashMap> | 208 template <class HashMap> |
205 inline bool | 209 inline bool |
206 HashMapEquality(const HashMap& map_a, | 210 HashMapEquality(const HashMap& map_a, |
207 const HashMap& map_b) { | 211 const HashMap& map_b) { |
208 if (map_a.size() != map_b.size()) return false; | 212 if (map_a.size() != map_b.size()) return false; |
209 for (typename HashMap::const_iterator i = map_a.begin(); | 213 for (typename HashMap::const_iterator i = map_a.begin(); |
210 i != map_a.end(); ++i) { | 214 i != map_a.end(); ++i) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 // Translates a set into a vector. | 443 // Translates a set into a vector. |
440 template<typename T> | 444 template<typename T> |
441 std::vector<T> SetToVector(const std::set<T>& values) { | 445 std::vector<T> SetToVector(const std::set<T>& values) { |
442 std::vector<T> result; | 446 std::vector<T> result; |
443 result.reserve(values.size()); | 447 result.reserve(values.size()); |
444 result.insert(result.begin(), values.begin(), values.end()); | 448 result.insert(result.begin(), values.begin(), values.end()); |
445 return result; | 449 return result; |
446 } | 450 } |
447 | 451 |
448 #endif // CHROME_COMMON_STL_UTIL_INL_H__ | 452 #endif // CHROME_COMMON_STL_UTIL_INL_H__ |
OLD | NEW |