Commit 093a29f9 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[base] Make Container in flat_tree configurable

This change modifies base::flat_tree, base::flat_set and base::flat_map
to make the underlying container type configurable. This is consistent
with the standardization proposal.

The default container continues to be a std::vector.

Bug: 682254
Change-Id: Ic430e97fa981f21b3f8b20a9e83c153340ea258b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510249Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823293}
parent ccc1b865
This diff is collapsed.
...@@ -6,14 +6,16 @@ ...@@ -6,14 +6,16 @@
#define BASE_CONTAINERS_FLAT_SET_H_ #define BASE_CONTAINERS_FLAT_SET_H_
#include <functional> #include <functional>
#include <vector>
#include "base/containers/flat_tree.h" #include "base/containers/flat_tree.h"
#include "base/functional/identity.h"
#include "base/template_util.h" #include "base/template_util.h"
namespace base { namespace base {
// flat_set is a container with a std::set-like interface that stores its // flat_set is a container with a std::set-like interface that stores its
// contents in a sorted vector. // contents in a sorted container, by default a vector.
// //
// Its implementation mostly tracks the corresponding standardization proposal // Its implementation mostly tracks the corresponding standardization proposal
// https://wg21.link/P1222. // https://wg21.link/P1222.
...@@ -37,7 +39,7 @@ namespace base { ...@@ -37,7 +39,7 @@ namespace base {
// //
// - Iterators are invalidated across mutations. // - Iterators are invalidated across mutations.
// - If possible, construct a flat_set in one operation by inserting into // - If possible, construct a flat_set in one operation by inserting into
// a std::vector and moving that vector into the flat_set constructor. // a container and moving that container into the flat_set constructor.
// - For multiple removals use base::EraseIf() which is O(n) rather than // - For multiple removals use base::EraseIf() which is O(n) rather than
// O(n * removed_items). // O(n * removed_items).
// //
...@@ -52,9 +54,9 @@ namespace base { ...@@ -52,9 +54,9 @@ namespace base {
// flat_set(flat_set&&); // flat_set(flat_set&&);
// flat_set(InputIterator first, InputIterator last, // flat_set(InputIterator first, InputIterator last,
// const Compare& compare = Compare()); // const Compare& compare = Compare());
// flat_set(const std::vector<Key>& items, // flat_set(const container_type& items,
// const Compare& compare = Compare()); // const Compare& compare = Compare());
// flat_set(std::vector<Key>&& items, // flat_set(container_type&& items,
// const Compare& compare = Compare()); // Re-use storage. // const Compare& compare = Compare()); // Re-use storage.
// flat_set(std::initializer_list<value_type> ilist, // flat_set(std::initializer_list<value_type> ilist,
// const Compare& comp = Compare()); // const Compare& comp = Compare());
...@@ -64,10 +66,10 @@ namespace base { ...@@ -64,10 +66,10 @@ namespace base {
// InputIterator first, InputIterator last, // InputIterator first, InputIterator last,
// const Compare& compare = Compare()); // const Compare& compare = Compare());
// flat_set(sorted_unique_t, // flat_set(sorted_unique_t,
// const std::vector<Key>& items, // const container_type& items,
// const Compare& compare = Compare()); // const Compare& compare = Compare());
// flat_set(sorted_unique_t, // flat_set(sorted_unique_t,
// std::vector<Key>&& items, // container_type&& items,
// const Compare& compare = Compare()); // Re-use storage. // const Compare& compare = Compare()); // Re-use storage.
// flat_set(sorted_unique_t, // flat_set(sorted_unique_t,
// std::initializer_list<value_type> ilist, // std::initializer_list<value_type> ilist,
...@@ -113,8 +115,8 @@ namespace base { ...@@ -113,8 +115,8 @@ namespace base {
// iterator emplace_hint(const_iterator, Args&&...); // iterator emplace_hint(const_iterator, Args&&...);
// //
// Underlying type functions: // Underlying type functions:
// underlying_type extract() &&; // container_type extract() &&;
// void replace(underlying_type&&); // void replace(container_type&&);
// //
// Erase functions: // Erase functions:
// iterator erase(iterator); // iterator erase(iterator);
...@@ -148,12 +150,11 @@ namespace base { ...@@ -148,12 +150,11 @@ namespace base {
// bool operator>=(const flat_set&, const flat_set); // bool operator>=(const flat_set&, const flat_set);
// bool operator<=(const flat_set&, const flat_set); // bool operator<=(const flat_set&, const flat_set);
// //
template <class Key, class Compare = std::less<>> template <class Key,
using flat_set = typename ::base::internal::flat_tree< class Compare = std::less<>,
Key, class Container = std::vector<Key>>
Key, using flat_set = typename ::base::internal::
::base::internal::GetKeyFromValueIdentity<Key>, flat_tree<Key, base::identity, Compare, Container>;
Compare>;
} // namespace base } // namespace base
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment