summaryrefslogtreecommitdiff
path: root/absl/container/btree_map.h
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2021-11-15 11:29:23 -0800
committerGravatar dinord <dino.radakovich@gmail.com>2021-11-15 14:43:32 -0500
commitd587c966ed86dc3b94362444e2b20fc3c5c4224e (patch)
tree2a5d864e2389ec1425463c1ac40a73cb06216c78 /absl/container/btree_map.h
parentf2dbd918d8d08529800eb72f23bd2829f92104a4 (diff)
Export of internal Abseil changes
-- 355b8f7b0070b005d53d94ee4180e95559ba2c88 by Derek Mauro <dmauro@google.com>: Documentation: don't define absl::Status::ok() in terms of itself Fixes #1058 PiperOrigin-RevId: 410035651 -- 31c512c834b3a8979297adc5006c3727a3c6554b by Evan Brown <ezb@google.com>: Cleanup: move set_params/set_slot_policy into btree_set.h and move map_params into btree_map.h. Also change some `sizeof(value_type)`s to `sizeof(slot_type)`s and update some comments/variable names referring to values to refer to slots as appropriate in btree.h. Motivation: preliminary cleanup towards node_btree_*. PiperOrigin-RevId: 409991342 -- 3129ca320d61a82f1c9ee8c02a23d25024eea4ab by Abseil Team <absl-team@google.com>: Use simpler implementation for AddressIsReadable. In particular, current solution doesn't work on systems configured with large pid_t space. PiperOrigin-RevId: 409397716 -- f71067f7494b19ce4a2e1df730b934dc931c51b2 by Martijn Vels <mvels@google.com>: Add Span dependency PiperOrigin-RevId: 409198889 GitOrigin-RevId: 355b8f7b0070b005d53d94ee4180e95559ba2c88 Change-Id: I7f4df3ec7739fdfde61d8ba983f07a08f6f1c7d7
Diffstat (limited to 'absl/container/btree_map.h')
-rw-r--r--absl/container/btree_map.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/absl/container/btree_map.h b/absl/container/btree_map.h
index 96ebcb77..4eafe062 100644
--- a/absl/container/btree_map.h
+++ b/absl/container/btree_map.h
@@ -56,6 +56,14 @@
namespace absl {
ABSL_NAMESPACE_BEGIN
+namespace container_internal {
+
+template <typename Key, typename Data, typename Compare, typename Alloc,
+ int TargetNodeSize, bool Multi>
+struct map_params;
+
+} // namespace container_internal
+
// absl::btree_map<>
//
// An `absl::btree_map<K, V>` is an ordered associative container of
@@ -812,6 +820,58 @@ void erase_if(btree_multimap<K, V, C, A> &map, Pred pred) {
}
}
+namespace container_internal {
+
+// A parameters structure for holding the type parameters for a btree_map.
+// Compare and Alloc should be nothrow copy-constructible.
+template <typename Key, typename Data, typename Compare, typename Alloc,
+ int TargetNodeSize, bool Multi>
+struct map_params : common_params<Key, Compare, Alloc, TargetNodeSize, Multi,
+ map_slot_policy<Key, Data>> {
+ using super_type = typename map_params::common_params;
+ using mapped_type = Data;
+ // This type allows us to move keys when it is safe to do so. It is safe
+ // for maps in which value_type and mutable_value_type are layout compatible.
+ using slot_policy = typename super_type::slot_policy;
+ using slot_type = typename super_type::slot_type;
+ using value_type = typename super_type::value_type;
+ using init_type = typename super_type::init_type;
+
+ using original_key_compare = typename super_type::original_key_compare;
+ // Reference: https://en.cppreference.com/w/cpp/container/map/value_compare
+ class value_compare {
+ template <typename Params>
+ friend class btree;
+
+ protected:
+ explicit value_compare(original_key_compare c) : comp(std::move(c)) {}
+
+ original_key_compare comp; // NOLINT
+
+ public:
+ auto operator()(const value_type &lhs, const value_type &rhs) const
+ -> decltype(comp(lhs.first, rhs.first)) {
+ return comp(lhs.first, rhs.first);
+ }
+ };
+ using is_map_container = std::true_type;
+
+ template <typename V>
+ static auto key(const V &value) -> decltype(value.first) {
+ return value.first;
+ }
+ static const Key &key(const slot_type *s) { return slot_policy::key(s); }
+ static const Key &key(slot_type *s) { return slot_policy::key(s); }
+ // For use in node handle.
+ static auto mutable_key(slot_type *s)
+ -> decltype(slot_policy::mutable_key(s)) {
+ return slot_policy::mutable_key(s);
+ }
+ static mapped_type &value(value_type *value) { return value->second; }
+};
+
+} // namespace container_internal
+
ABSL_NAMESPACE_END
} // namespace absl