Chromium Code Reviews| Index: base/containers/flat_set.h |
| diff --git a/base/containers/flat_set.h b/base/containers/flat_set.h |
| index ae444c2c8e21c38ebec295ee023a365b84b3e057..5e59c39924277eb5f1d796b156394a7a9a3ab0cf 100644 |
| --- a/base/containers/flat_set.h |
| +++ b/base/containers/flat_set.h |
| @@ -33,12 +33,13 @@ namespace base { |
| // TODO(dyaroshev): improve the interface to better support this pattern |
| // (crbug.com/682254). |
| // * Sets where mutating happens in big bulks: use erase(std::remove()) idiom |
| -// for erasing many elements. Insertion is harder - consider set operations |
| -// or building a new vector. Set operations can be slow if one of the sets |
| -// is considerably bigger. Also be aware that beating performance of |
| -// sort + unique (implementation of flat_set's constructor) is hard, clever |
| -// merge of many sets might not win. Generally avoid inserting into flat set |
| -// without benchmarks. |
| +// for erasing many elements. If possible - use supplied for flat_set |
| +// overload of base::EraseIf. Insertion is harder - consider set operations |
|
dyaroshev
2017/03/03 23:16:54
I'm not sure how to formulate this thought.
Peter Kasting
2017/03/03 23:27:30
"Sets where mutating happens in bulk operations: t
dyaroshev
2017/03/04 00:32:49
Done.
|
| +// or building a new vector. Set operations can be slow if one of the sets is |
| +// considerably bigger. Also be aware that beating performance of sort + |
| +// unique (implementation of flat_set's constructor) is hard, clever merge of |
| +// many sets might not win. Generally avoid inserting into flat set without |
| +// benchmarks. |
| // * Copying and iterating. |
| // * Set operations (union/intersect etc). |
| // |
| @@ -217,7 +218,8 @@ class flat_set { |
| // erase(key) may take O(size) + O(log(size)). |
| // |
| // Prefer the erase(std::remove(), end()) idiom for deleting multiple |
|
danakj
2017/03/03 23:51:22
Like peter said above just say to use base::EraseI
dyaroshev
2017/03/04 00:32:49
Slightly extended it. Is it ok?
|
| - // elements. |
| + // elements. If possible use supplied base::EraseIf overload. |
| + // |
| iterator erase(const_iterator position); |
| iterator erase(const_iterator first, const_iterator last); |
| @@ -657,6 +659,18 @@ void flat_set<Key, Compare>::swap(flat_set& other) { |
| std::swap(impl_, other.impl_); |
| } |
| +// ---------------------------------------------------------------------------- |
| +// Free functions. |
| + |
| +// Erases all elements that match predicate. It has O(size) complexity. |
| + |
|
danakj
2017/03/03 23:51:22
no whitespace here
dyaroshev
2017/03/04 00:32:49
Done.
|
| +template <typename Key, typename Compare, typename Predicate> |
| +void EraseIf(base::flat_set<Key, Compare>& container, Predicate pred) { |
| + container.erase( |
| + std::remove_if(std::begin(container), std::end(container), pred), |
|
danakj
2017/03/03 23:51:22
it's a bit less verbose to use container.begin() a
dyaroshev
2017/03/04 00:32:49
Done.
|
| + std::end(container)); |
| +} |
| + |
| } // namespace base |
| #endif // BASE_CONTAINERS_FLAT_SET_H_ |