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): | |
42 // flat_map(InputIterator first, InputIterator last, | |
43 // const Compare& compare = Compare()); | |
44 // flat_map(const flat_map&); | |
45 // flat_map(flat_map&&); | |
46 // flat_map(std::vector<value_type>&&); | |
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 | |
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, |
145 const Compare& comp = Compare()); | 157 const Compare& comp = Compare()); |
146 | 158 |
147 flat_map(const flat_map&); | 159 flat_map(const flat_map&); |
148 flat_map(flat_map&&); | 160 flat_map(flat_map&&); |
149 | 161 |
150 // Not stable in the presence of duplicates in the initializer list. | 162 flat_map(std::vector<value_type>&& items, |
dyaroshev
2017/03/31 07:46:52
Accept by value and mke it explicit please.
| |
163 const key_compare& comp = key_compare()); | |
164 | |
151 flat_map(std::initializer_list<value_type> ilist, | 165 flat_map(std::initializer_list<value_type> ilist, |
152 const Compare& comp = Compare()); | 166 const Compare& comp = Compare()); |
153 | 167 |
154 ~flat_map(); | 168 ~flat_map(); |
155 | 169 |
156 // -------------------------------------------------------------------------- | 170 // -------------------------------------------------------------------------- |
157 // Assignments. | 171 // Assignments. |
158 // | 172 // |
159 // Assume that move assignment invalidates iterators and references. | 173 // Assume that move assignment invalidates iterators and references. |
160 | 174 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 : tree(first, last, comp) {} | 215 : tree(first, last, comp) {} |
202 | 216 |
203 template <class Key, class Mapped, class Compare> | 217 template <class Key, class Mapped, class Compare> |
204 flat_map<Key, Mapped, Compare>::flat_map(const flat_map&) = default; | 218 flat_map<Key, Mapped, Compare>::flat_map(const flat_map&) = default; |
205 | 219 |
206 template <class Key, class Mapped, class Compare> | 220 template <class Key, class Mapped, class Compare> |
207 flat_map<Key, Mapped, Compare>::flat_map(flat_map&&) = default; | 221 flat_map<Key, Mapped, Compare>::flat_map(flat_map&&) = default; |
208 | 222 |
209 template <class Key, class Mapped, class Compare> | 223 template <class Key, class Mapped, class Compare> |
210 flat_map<Key, Mapped, Compare>::flat_map( | 224 flat_map<Key, Mapped, Compare>::flat_map( |
225 std::vector<value_type>&& items, | |
226 const key_compare& comp = key_compare()) | |
227 : tree(std::move(items), comp) {} | |
228 | |
229 template <class Key, class Mapped, class Compare> | |
230 flat_map<Key, Mapped, Compare>::flat_map( | |
211 std::initializer_list<value_type> ilist, | 231 std::initializer_list<value_type> ilist, |
212 const Compare& comp) | 232 const Compare& comp) |
213 : flat_map(std::begin(ilist), std::end(ilist), comp) {} | 233 : flat_map(std::begin(ilist), std::end(ilist), comp) {} |
214 | 234 |
215 template <class Key, class Mapped, class Compare> | 235 template <class Key, class Mapped, class Compare> |
216 flat_map<Key, Mapped, Compare>::~flat_map() = default; | 236 flat_map<Key, Mapped, Compare>::~flat_map() = default; |
217 | 237 |
218 // ---------------------------------------------------------------------------- | 238 // ---------------------------------------------------------------------------- |
219 // Assignments. | 239 // Assignments. |
220 | 240 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 // General operations. | 277 // General operations. |
258 | 278 |
259 template <class Key, class Mapped, class Compare> | 279 template <class Key, class Mapped, class Compare> |
260 void flat_map<Key, Mapped, Compare>::swap(flat_map& other) { | 280 void flat_map<Key, Mapped, Compare>::swap(flat_map& other) { |
261 tree::swap(other); | 281 tree::swap(other); |
262 } | 282 } |
263 | 283 |
264 } // namespace base | 284 } // namespace base |
265 | 285 |
266 #endif // BASE_CONTAINERS_FLAT_MAP_H_ | 286 #endif // BASE_CONTAINERS_FLAT_MAP_H_ |
OLD | NEW |