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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/omnibox/browser/url_index_private_data.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/containers/flat_tree.h
diff --git a/base/containers/flat_tree.h b/base/containers/flat_tree.h
index 8e85f2377655f954c585be08bea9749edd79240c..5be811b047fc82c9d64176802f5b5f69c0ead5a0 100644
--- a/base/containers/flat_tree.h
+++ b/base/containers/flat_tree.h
@@ -200,6 +200,24 @@ class flat_tree {
iterator insert(const_iterator position_hint, const value_type& x);
iterator insert(const_iterator position_hint, value_type&& x);
+ template <typename I>
+ void insert_by_one(I first, I last) {
+ std::copy(first, last, std::inserter(*this, end()));
+ }
+
+ template <typename I>
+ void insert_merge(I first, I last) {
+ size_type original_size = size();
+ impl_.body_.insert(end(), first, last);
+ iterator new_elements = begin() + original_size;
+ std::stable_sort(new_elements, end(), value_compare());
+ std::inplace_merge(begin(), new_elements, end());
+ auto comparator = [this](const value_type& lhs, const value_type& rhs) {
+ return !value_comp()(lhs, rhs);
+ };
+ erase(std::unique(begin(), end(), comparator), end());
+ }
+
template <class... Args>
std::pair<iterator, bool> emplace(Args&&... args);
« 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