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

Unified Diff: base/containers/flat_set.h

Issue 2333253002: flat containers prototype (Closed)
Patch Set: Fixing performance bug in insert(It, It) Created 4 years, 1 month 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
Index: base/containers/flat_set.h
diff --git a/base/containers/flat_set.h b/base/containers/flat_set.h
new file mode 100644
index 0000000000000000000000000000000000000000..54655afd46e8a7504b04f478efe385f0c19a3d60
--- /dev/null
+++ b/base/containers/flat_set.h
@@ -0,0 +1,59 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_CONTAINERS_FLAT_SET_H_
+#define BASE_CONTAINERS_FLAT_SET_H_
+
+#include <algorithm>
+#include <functional>
+#include <set>
+#include <utility>
+#include <vector>
+
+#include "base/containers/flat_sorted_container_base.h"
+#include "base/logging.h"
+
+namespace base {
+
+namespace internal {
+
+template <typename Key, class Compare>
+struct set_compare : private Compare {
+ using key_type = Key;
+ using value_type = Key;
+
+ using Compare::operator();
+
+ template <typename Lhs, typename Rhs>
+ bool equal(const Lhs& lhs, const Rhs& rhs) {
+ return !operator()(lhs, rhs) && !operator()(rhs, lhs);
+ }
+
+ const key_type& key_from_value(const value_type& value) { return value; }
+
+ key_type& key_from_value(value_type& value) { return value; } // NOLINT
+};
+
+} // namespace internal
+
+// std::vector is not particulary friendly with const value type,
+// so, unlike std::map, we use non const Key
+template <typename Key,
+ class Compare = std::less<Key>,
+ class UnderlyingType = std::vector<Key>>
+class flat_set : public internal::flat_sorted_container_base<
+ internal::set_compare<Key, Compare>,
+ UnderlyingType> {
+ using base_type =
+ internal::flat_sorted_container_base<internal::set_compare<Key, Compare>,
+ UnderlyingType>;
+
+ public:
+ using base_type::base_type;
+ using std_set = std::set<Key>;
+};
+
+} // namespace base
+
+#endif // BASE_CONTAINERS_FLAT_SET_H_

Powered by Google App Engine
This is Rietveld 408576698