OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_CONTAINERS_FLAT_SET_H_ | 5 #ifndef BASE_CONTAINERS_FLAT_SET_H_ |
6 #define BASE_CONTAINERS_FLAT_SET_H_ | 6 #define BASE_CONTAINERS_FLAT_SET_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <functional> | 9 #include <functional> |
10 #include <utility> | 10 #include <utility> |
(...skipping 24 matching lines...) Expand all Loading... |
35 // * Sets where mutating happens in big bulks: use erase(std::remove()) idiom | 35 // * Sets where mutating happens in big bulks: use erase(std::remove()) idiom |
36 // for erasing many elements. Insertion is harder - consider set operations | 36 // for erasing many elements. Insertion is harder - consider set operations |
37 // or building a new vector. Set operations can be slow if one of the sets | 37 // or building a new vector. Set operations can be slow if one of the sets |
38 // is considerably bigger. Also be aware that beating performance of | 38 // is considerably bigger. Also be aware that beating performance of |
39 // sort + unique (implementation of flat_set's constructor) is hard, clever | 39 // sort + unique (implementation of flat_set's constructor) is hard, clever |
40 // merge of many sets might not win. Generally avoid inserting into flat set | 40 // merge of many sets might not win. Generally avoid inserting into flat set |
41 // without benchmarks. | 41 // without benchmarks. |
42 // * Copying and iterating. | 42 // * Copying and iterating. |
43 // * Set operations (union/intersect etc). | 43 // * Set operations (union/intersect etc). |
44 // | 44 // |
| 45 // Prefer to build a new flat_set from a std::vector (or similar) instead of |
| 46 // calling insert() repeatedly, which would have O(size^2) complexity. |
| 47 // |
45 // TODO(dyaroshev): develop standalone benchmarks to find performance boundaries | 48 // TODO(dyaroshev): develop standalone benchmarks to find performance boundaries |
46 // for different types of sets crbug.com/682215. | 49 // for different types of sets crbug.com/682215. |
47 // | 50 // |
48 // If you do write a benchmark that significantly depends on using sets please | 51 // If you do write a benchmark that significantly depends on using sets please |
49 // share your results at: | 52 // share your results at: |
50 // https://groups.google.com/a/chromium.org/forum/#!searchin/chromium-dev/vector
$20based/chromium-dev/4uQMma9vj9w/HaQ-WvMOAwAJ | 53 // https://groups.google.com/a/chromium.org/forum/#!searchin/chromium-dev/vector
$20based/chromium-dev/4uQMma9vj9w/HaQ-WvMOAwAJ |
51 // | 54 // |
52 // Important usability aspects: | 55 // Important usability aspects: |
53 // * flat_set implements std::set interface from C++11 where possible. It | 56 // * flat_set implements std::set interface from C++11 where possible. It |
54 // also has reserve(), capacity() and shrink_to_fit() from std::vector. | 57 // also has reserve(), capacity() and shrink_to_fit() from std::vector. |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 const_reverse_iterator rend() const; | 185 const_reverse_iterator rend() const; |
183 const_reverse_iterator crend() const; | 186 const_reverse_iterator crend() const; |
184 | 187 |
185 // -------------------------------------------------------------------------- | 188 // -------------------------------------------------------------------------- |
186 // Insert operations. | 189 // Insert operations. |
187 // | 190 // |
188 // Assume that every operation invalidates iterators and references. | 191 // Assume that every operation invalidates iterators and references. |
189 // Insertion of one element can take O(size). See the Notes section in the | 192 // Insertion of one element can take O(size). See the Notes section in the |
190 // class comments on why we do not currently implement range insertion. | 193 // class comments on why we do not currently implement range insertion. |
191 // Capacity of flat_set grows in an implementation-defined manner. | 194 // Capacity of flat_set grows in an implementation-defined manner. |
| 195 // |
| 196 // NOTE: Prefer to build a new flat_set from a std::vector (or similar) |
| 197 // instead of calling insert() repeatedly. |
192 | 198 |
193 std::pair<iterator, bool> insert(const value_type& val); | 199 std::pair<iterator, bool> insert(const value_type& val); |
194 std::pair<iterator, bool> insert(value_type&& val); | 200 std::pair<iterator, bool> insert(value_type&& val); |
195 | 201 |
196 iterator insert(const_iterator position_hint, const value_type& x); | 202 iterator insert(const_iterator position_hint, const value_type& x); |
197 iterator insert(const_iterator position_hint, value_type&& x); | 203 iterator insert(const_iterator position_hint, value_type&& x); |
198 | 204 |
199 template <class... Args> | 205 template <class... Args> |
200 std::pair<iterator, bool> emplace(Args&&... args); | 206 std::pair<iterator, bool> emplace(Args&&... args); |
201 | 207 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // General operations. | 653 // General operations. |
648 | 654 |
649 template <class Key, class Compare> | 655 template <class Key, class Compare> |
650 void flat_set<Key, Compare>::swap(flat_set& other) { | 656 void flat_set<Key, Compare>::swap(flat_set& other) { |
651 std::swap(impl_, other.impl_); | 657 std::swap(impl_, other.impl_); |
652 } | 658 } |
653 | 659 |
654 } // namespace base | 660 } // namespace base |
655 | 661 |
656 #endif // BASE_CONTAINERS_FLAT_SET_H_ | 662 #endif // BASE_CONTAINERS_FLAT_SET_H_ |
OLD | NEW |