Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: base/containers/flat_tree.h

Issue 2862813002: Insertion by one sometimes gives drammatically better results than (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | components/omnibox/browser/url_index_private_data.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_TREE_H_ 5 #ifndef BASE_CONTAINERS_FLAT_TREE_H_
6 #define BASE_CONTAINERS_FLAT_TREE_H_ 6 #define BASE_CONTAINERS_FLAT_TREE_H_
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // 193 //
194 // NOTE: Prefer to build a new flat_tree from a std::vector (or similar) 194 // NOTE: Prefer to build a new flat_tree from a std::vector (or similar)
195 // instead of calling insert() repeatedly. 195 // instead of calling insert() repeatedly.
196 196
197 std::pair<iterator, bool> insert(const value_type& val); 197 std::pair<iterator, bool> insert(const value_type& val);
198 std::pair<iterator, bool> insert(value_type&& val); 198 std::pair<iterator, bool> insert(value_type&& val);
199 199
200 iterator insert(const_iterator position_hint, const value_type& x); 200 iterator insert(const_iterator position_hint, const value_type& x);
201 iterator insert(const_iterator position_hint, value_type&& x); 201 iterator insert(const_iterator position_hint, value_type&& x);
202 202
203 template <typename I>
204 void insert_by_one(I first, I last) {
205 std::copy(first, last, std::inserter(*this, end()));
206 }
207
208 template <typename I>
209 void insert_merge(I first, I last) {
210 size_type original_size = size();
211 impl_.body_.insert(end(), first, last);
212 iterator new_elements = begin() + original_size;
213 std::stable_sort(new_elements, end(), value_compare());
214 std::inplace_merge(begin(), new_elements, end());
215 auto comparator = [this](const value_type& lhs, const value_type& rhs) {
216 return !value_comp()(lhs, rhs);
217 };
218 erase(std::unique(begin(), end(), comparator), end());
219 }
220
203 template <class... Args> 221 template <class... Args>
204 std::pair<iterator, bool> emplace(Args&&... args); 222 std::pair<iterator, bool> emplace(Args&&... args);
205 223
206 template <class... Args> 224 template <class... Args>
207 iterator emplace_hint(const_iterator position_hint, Args&&... args); 225 iterator emplace_hint(const_iterator position_hint, Args&&... args);
208 226
209 // -------------------------------------------------------------------------- 227 // --------------------------------------------------------------------------
210 // Erase operations. 228 // Erase operations.
211 // 229 //
212 // Assume that every operation invalidates iterators and references. 230 // Assume that every operation invalidates iterators and references.
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 void EraseIf(base::internal::flat_tree<Key, Value, GetKeyFromValue, KeyCompare>& 786 void EraseIf(base::internal::flat_tree<Key, Value, GetKeyFromValue, KeyCompare>&
769 container, 787 container,
770 Predicate pred) { 788 Predicate pred) {
771 container.erase(std::remove_if(container.begin(), container.end(), pred), 789 container.erase(std::remove_if(container.begin(), container.end(), pred),
772 container.end()); 790 container.end());
773 } 791 }
774 792
775 } // namespace base 793 } // namespace base
776 794
777 #endif // BASE_CONTAINERS_FLAT_TREE_H_ 795 #endif // BASE_CONTAINERS_FLAT_TREE_H_
OLDNEW
« no previous file with comments | « no previous file | components/omnibox/browser/url_index_private_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698