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_MAP_H_ | 5 #ifndef BASE_CONTAINERS_FLAT_MAP_H_ |
6 #define BASE_CONTAINERS_FLAT_MAP_H_ | 6 #define BASE_CONTAINERS_FLAT_MAP_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/containers/flat_tree.h" | 10 #include "base/containers/flat_tree.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 // sorted containers that stores its elements in contiguous memory (a vector). | 31 // sorted containers that stores its elements in contiguous memory (a vector). |
32 // | 32 // |
33 // Additional documentation and usage advice is in flat_set.h. | 33 // Additional documentation and usage advice is in flat_set.h. |
34 // | 34 // |
35 // DOCUMENTATION | 35 // DOCUMENTATION |
36 // | 36 // |
37 // Most of the core functionality is inherited from flat_tree. Please see | 37 // Most of the core functionality is inherited from flat_tree. Please see |
38 // flat_tree.h for more details for most of these functions. As a quick | 38 // flat_tree.h for more details for most of these functions. As a quick |
39 // reference, the functions available are: | 39 // reference, the functions available are: |
40 // | 40 // |
41 // Constructors (inputs need not be sorted, first of duplicates will be kept): | |
danakj
2017/04/05 21:33:42
I don't understand this comment in the presence of
brettw
2017/04/07 21:59:03
Done.
| |
42 // flat_map(InputIterator first, InputIterator last, | |
43 // FlatContainerDupes, const Compare& compare = Compare()); | |
44 // flat_map(const flat_map&); | |
45 // flat_map(flat_map&&); | |
46 // flat_map(std::vector<value_type>, FlatContainerDupes); // Re-use storage. | |
47 // flat_map(std::initializer_list<value_type> ilist, | |
48 // const Compare& comp = Compare()); | |
49 // | |
41 // Assignment functions: | 50 // Assignment functions: |
42 // flat_map& operator=(const flat_map&); | 51 // flat_map& operator=(const flat_map&); |
43 // flat_map& operator=(flat_map&&); | 52 // flat_map& operator=(flat_map&&); |
44 // flat_map& operator=(initializer_list<pair<Key, Mapped>>); | 53 // flat_map& operator=(initializer_list<pair<Key, Mapped>>); |
45 // | 54 // |
46 // Memory management functions: | 55 // Memory management functions: |
47 // void reserve(size_t); | 56 // void reserve(size_t); |
48 // size_t capacity() const; | 57 // size_t capacity() const; |
49 // void shrink_to_fit(); | 58 // void shrink_to_fit(); |
50 // | 59 // |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 // Search functions: | 97 // Search functions: |
89 // size_t count(const Key&) const; | 98 // size_t count(const Key&) const; |
90 // iterator find(const Key&); | 99 // iterator find(const Key&); |
91 // const_iterator find(const Key&) const; | 100 // const_iterator find(const Key&) const; |
92 // pair<iterator, iterator> equal_range(Key&) | 101 // pair<iterator, iterator> equal_range(Key&) |
93 // iterator lower_bound(const Key&); | 102 // iterator lower_bound(const Key&); |
94 // const_iterator lower_bound(const Key&) const; | 103 // const_iterator lower_bound(const Key&) const; |
95 // iterator upper_bound(const Key&); | 104 // iterator upper_bound(const Key&); |
96 // const_iterator upper_bound(const Key&) const; | 105 // const_iterator upper_bound(const Key&) const; |
97 // | 106 // |
98 // General functions | 107 // General functions: |
99 // void swap(flat_map&&) | 108 // void swap(flat_map&&) |
100 // | 109 // |
101 // Non-member operators: | 110 // Non-member operators: |
102 // bool operator==(const flat_map&, const flat_map); | 111 // bool operator==(const flat_map&, const flat_map); |
103 // bool operator!=(const flat_map&, const flat_map); | 112 // bool operator!=(const flat_map&, const flat_map); |
104 // bool operator<(const flat_map&, const flat_map); | 113 // bool operator<(const flat_map&, const flat_map); |
105 // bool operator>(const flat_map&, const flat_map); | 114 // bool operator>(const flat_map&, const flat_map); |
106 // bool operator>=(const flat_map&, const flat_map); | 115 // bool operator>=(const flat_map&, const flat_map); |
107 // bool operator<=(const flat_map&, const flat_map); | 116 // bool operator<=(const flat_map&, const flat_map); |
108 // | 117 // |
(...skipping 18 matching lines...) Expand all Loading... | |
127 using value_type = typename tree::value_type; | 136 using value_type = typename tree::value_type; |
128 | 137 |
129 // -------------------------------------------------------------------------- | 138 // -------------------------------------------------------------------------- |
130 // Lifetime. | 139 // Lifetime. |
131 // | 140 // |
132 // Constructors that take range guarantee O(N * log(N)) + O(N) complexity | 141 // Constructors that take range guarantee O(N * log(N)) + O(N) complexity |
133 // (N is a range length). Thr range constructors are NOT stable. If there are | 142 // (N is a range length). Thr range constructors are NOT stable. If there are |
134 // duplicates an arbitrary one will be chosen. | 143 // duplicates an arbitrary one will be chosen. |
135 // | 144 // |
136 // Assume that move constructors invalidate iterators and references. | 145 // Assume that move constructors invalidate iterators and references. |
146 // | |
147 // The constructors that take ranges, lists, and vectors do not require that | |
148 // the input be sorted. If there are duplcates, the first one in the input | |
danakj
2017/04/05 21:33:42
Same here
brettw
2017/04/07 21:59:03
Done.
| |
149 // will be selected. | |
137 | 150 |
138 flat_map(); | 151 flat_map(); |
139 explicit flat_map(const Compare& comp); | 152 explicit flat_map(const Compare& comp); |
140 | 153 |
141 // Not stable in the presence of duplicates in the initializer list. | |
142 template <class InputIterator> | 154 template <class InputIterator> |
143 flat_map(InputIterator first, | 155 flat_map(InputIterator first, |
144 InputIterator last, | 156 InputIterator last, |
157 FlatContainerDupes dupe_handling, | |
145 const Compare& comp = Compare()); | 158 const Compare& comp = Compare()); |
146 | 159 |
147 flat_map(const flat_map&); | 160 flat_map(const flat_map&); |
148 flat_map(flat_map&&); | 161 flat_map(flat_map&&); |
149 | 162 |
150 // Not stable in the presence of duplicates in the initializer list. | 163 flat_map(std::vector<value_type> items, |
164 FlatContainerDupes dupe_handling, | |
165 const Compare& comp = Compare()); | |
166 | |
167 // Takes the first if there are duplicates in the initializer list. | |
danakj
2017/04/05 21:33:42
and same here
brettw
2017/04/07 21:59:03
Done.
| |
151 flat_map(std::initializer_list<value_type> ilist, | 168 flat_map(std::initializer_list<value_type> ilist, |
169 FlatContainerDupes dupe_handling, | |
152 const Compare& comp = Compare()); | 170 const Compare& comp = Compare()); |
153 | 171 |
154 ~flat_map(); | 172 ~flat_map(); |
155 | 173 |
156 // -------------------------------------------------------------------------- | 174 // -------------------------------------------------------------------------- |
157 // Assignments. | 175 // Assignments. |
158 // | 176 // |
159 // Assume that move assignment invalidates iterators and references. | 177 // Assume that move assignment invalidates iterators and references. |
160 | 178 |
161 flat_map& operator=(const flat_map&); | 179 flat_map& operator=(const flat_map&); |
162 flat_map& operator=(flat_map&&); | 180 flat_map& operator=(flat_map&&); |
163 // Not stable in the presence of duplicates in the initializer list. | 181 // Takes the first if there are duplicates in the initializer list. |
164 flat_map& operator=(std::initializer_list<value_type> ilist); | 182 flat_map& operator=(std::initializer_list<value_type> ilist); |
165 | 183 |
166 // -------------------------------------------------------------------------- | 184 // -------------------------------------------------------------------------- |
167 // Map-specific insert operations. | 185 // Map-specific insert operations. |
168 // | 186 // |
169 // Normal insert() functions are inherited from flat_tree. | 187 // Normal insert() functions are inherited from flat_tree. |
170 // | 188 // |
171 // Assume that every operation invalidates iterators and references. | 189 // Assume that every operation invalidates iterators and references. |
172 // Insertion of one element can take O(size). | 190 // Insertion of one element can take O(size). |
173 | 191 |
(...skipping 16 matching lines...) Expand all Loading... | |
190 template <class Key, class Mapped, class Compare> | 208 template <class Key, class Mapped, class Compare> |
191 flat_map<Key, Mapped, Compare>::flat_map() = default; | 209 flat_map<Key, Mapped, Compare>::flat_map() = default; |
192 | 210 |
193 template <class Key, class Mapped, class Compare> | 211 template <class Key, class Mapped, class Compare> |
194 flat_map<Key, Mapped, Compare>::flat_map(const Compare& comp) : tree(comp) {} | 212 flat_map<Key, Mapped, Compare>::flat_map(const Compare& comp) : tree(comp) {} |
195 | 213 |
196 template <class Key, class Mapped, class Compare> | 214 template <class Key, class Mapped, class Compare> |
197 template <class InputIterator> | 215 template <class InputIterator> |
198 flat_map<Key, Mapped, Compare>::flat_map(InputIterator first, | 216 flat_map<Key, Mapped, Compare>::flat_map(InputIterator first, |
199 InputIterator last, | 217 InputIterator last, |
218 FlatContainerDupes dupe_handling, | |
200 const Compare& comp) | 219 const Compare& comp) |
201 : tree(first, last, comp) {} | 220 : tree(first, last, dupe_handling, comp) {} |
202 | 221 |
203 template <class Key, class Mapped, class Compare> | 222 template <class Key, class Mapped, class Compare> |
204 flat_map<Key, Mapped, Compare>::flat_map(const flat_map&) = default; | 223 flat_map<Key, Mapped, Compare>::flat_map(const flat_map&) = default; |
205 | 224 |
206 template <class Key, class Mapped, class Compare> | 225 template <class Key, class Mapped, class Compare> |
207 flat_map<Key, Mapped, Compare>::flat_map(flat_map&&) = default; | 226 flat_map<Key, Mapped, Compare>::flat_map(flat_map&&) = default; |
208 | 227 |
209 template <class Key, class Mapped, class Compare> | 228 template <class Key, class Mapped, class Compare> |
229 flat_map<Key, Mapped, Compare>::flat_map(std::vector<value_type> items, | |
230 FlatContainerDupes dupe_handling, | |
231 const Compare& comp) | |
232 : tree(std::move(items), dupe_handling, comp) {} | |
233 | |
234 template <class Key, class Mapped, class Compare> | |
210 flat_map<Key, Mapped, Compare>::flat_map( | 235 flat_map<Key, Mapped, Compare>::flat_map( |
211 std::initializer_list<value_type> ilist, | 236 std::initializer_list<value_type> ilist, |
237 FlatContainerDupes dupe_handling, | |
212 const Compare& comp) | 238 const Compare& comp) |
213 : flat_map(std::begin(ilist), std::end(ilist), comp) {} | 239 : flat_map(std::begin(ilist), std::end(ilist), dupe_handling, comp) {} |
214 | 240 |
215 template <class Key, class Mapped, class Compare> | 241 template <class Key, class Mapped, class Compare> |
216 flat_map<Key, Mapped, Compare>::~flat_map() = default; | 242 flat_map<Key, Mapped, Compare>::~flat_map() = default; |
217 | 243 |
218 // ---------------------------------------------------------------------------- | 244 // ---------------------------------------------------------------------------- |
219 // Assignments. | 245 // Assignments. |
220 | 246 |
221 template <class Key, class Mapped, class Compare> | 247 template <class Key, class Mapped, class Compare> |
222 auto flat_map<Key, Mapped, Compare>::operator=(const flat_map&) | 248 auto flat_map<Key, Mapped, Compare>::operator=(const flat_map&) |
223 -> flat_map& = default; | 249 -> flat_map& = default; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 // General operations. | 283 // General operations. |
258 | 284 |
259 template <class Key, class Mapped, class Compare> | 285 template <class Key, class Mapped, class Compare> |
260 void flat_map<Key, Mapped, Compare>::swap(flat_map& other) { | 286 void flat_map<Key, Mapped, Compare>::swap(flat_map& other) { |
261 tree::swap(other); | 287 tree::swap(other); |
262 } | 288 } |
263 | 289 |
264 } // namespace base | 290 } // namespace base |
265 | 291 |
266 #endif // BASE_CONTAINERS_FLAT_MAP_H_ | 292 #endif // BASE_CONTAINERS_FLAT_MAP_H_ |
OLD | NEW |