manually merge some changes from abseil-cpp

This commit is contained in:
greg
2022-03-06 16:54:03 -05:00
parent cfacd26023
commit 73be7c2ab2
5 changed files with 174 additions and 63 deletions
+39 -17
View File
@@ -858,14 +858,14 @@ namespace priv {
// Upper bound for the available space for values. This is largest for leaf
// nodes, which have overhead of at least a pointer + 4 bytes (for storing
// 3 field_types and an enum).
kNodeValueSpace =
TargetNodeSize - /*minimum overhead=*/(sizeof(void *) + 4),
kNodeSlotSpace =
TargetNodeSize - /*minimum overhead=*/(sizeof(void *) + 4),
};
// This is an integral type large enough to hold as many
// ValueSize-values as will fit a node of TargetNodeSize bytes.
using node_count_type =
phmap::conditional_t<(kNodeValueSpace / sizeof(value_type) >
phmap::conditional_t<(kNodeSlotSpace / sizeof(slot_type) >
(std::numeric_limits<uint8_t>::max)()),
uint16_t, uint8_t>; // NOLINT
@@ -2501,7 +2501,7 @@ namespace priv {
"key comparison function must return phmap::{weak,strong}_ordering or "
"bool.");
// Test the assumption made in setting kNodeValueSpace.
// Test the assumption made in setting kNodeSlotSpace.
static_assert(node_type::MinimumOverhead() >= sizeof(void *) + 4,
"node space assumption incorrect");
@@ -3314,6 +3314,12 @@ namespace priv {
const_reverse_iterator crend() const { return tree_.rend(); }
// Lookup routines.
// ----------------
template <typename K = key_type>
size_type count(const key_arg<K> &key) const {
auto equal_range = this->equal_range(key);
return std::distance(equal_range.first, equal_range.second);
}
template <typename K = key_type>
iterator find(const key_arg<K> &key) {
return tree_.find(key);
@@ -3350,7 +3356,11 @@ namespace priv {
iterator erase(const_iterator first, const_iterator last) {
return tree_.erase(iterator(first), iterator(last)).second;
}
template <typename K = key_type>
size_type erase(const key_arg<K> &key) {
auto equal_range = this->equal_range(key);
return tree_.erase_range(equal_range.first, equal_range.second).first;
}
node_type extract(iterator position) {
// Use Move instead of Transfer, because the rebalancing code expects to
// have a valid object to scribble metadata bits on top of.
@@ -3449,6 +3459,10 @@ namespace priv {
const allocator_type &alloc = allocator_type())
: btree_set_container(init.begin(), init.end(), comp, alloc) {}
btree_set_container(std::initializer_list<init_type> init,
const allocator_type &alloc)
: btree_set_container(init.begin(), init.end(), alloc) {}
// Lookup routines.
template <typename K = key_type>
size_type count(const key_arg<K> &key) const {
@@ -3467,23 +3481,23 @@ namespace priv {
init_type v(std::forward<Args>(args)...);
return this->tree_.insert_unique(params_type::key(v), std::move(v));
}
iterator insert(const_iterator position, const value_type &x) {
iterator insert(const_iterator hint, const value_type &x) {
return this->tree_
.insert_hint_unique(iterator(position), params_type::key(x), x)
.insert_hint_unique(iterator(hint), params_type::key(x), x)
.first;
}
iterator insert(const_iterator position, value_type &&x) {
iterator insert(const_iterator hint, value_type &&x) {
return this->tree_
.insert_hint_unique(iterator(position), params_type::key(x),
.insert_hint_unique(iterator(hint), params_type::key(x),
std::move(x))
.first;
}
template <typename... Args>
iterator emplace_hint(const_iterator position, Args &&... args) {
iterator emplace_hint(const_iterator hint, Args &&... args) {
init_type v(std::forward<Args>(args)...);
return this->tree_
.insert_hint_unique(iterator(position), params_type::key(v),
.insert_hint_unique(iterator(hint), params_type::key(v),
std::move(v))
.first;
}
@@ -3705,11 +3719,11 @@ namespace priv {
iterator insert(value_type &&x) {
return this->tree_.insert_multi(std::move(x));
}
iterator insert(const_iterator position, const value_type &x) {
return this->tree_.insert_hint_multi(iterator(position), x);
iterator insert(const_iterator hint, const value_type &x) {
return this->tree_.insert_hint_multi(iterator(hint), x);
}
iterator insert(const_iterator position, value_type &&x) {
return this->tree_.insert_hint_multi(iterator(position), std::move(x));
iterator insert(const_iterator hint, value_type &&x) {
return this->tree_.insert_hint_multi(iterator(hint), std::move(x));
}
template <typename InputIterator>
void insert(InputIterator b, InputIterator e) {
@@ -3723,9 +3737,9 @@ namespace priv {
return this->tree_.insert_multi(init_type(std::forward<Args>(args)...));
}
template <typename... Args>
iterator emplace_hint(const_iterator position, Args &&... args) {
iterator emplace_hint(const_iterator hint, Args &&... args) {
return this->tree_.insert_hint_multi(
iterator(position), init_type(std::forward<Args>(args)...));
iterator(hint), init_type(std::forward<Args>(args)...));
}
iterator insert(node_type &&node) {
if (!node) return this->end();
@@ -3839,6 +3853,8 @@ namespace priv {
using Base::contains;
using Base::count;
using Base::equal_range;
using Base::lower_bound;
using Base::upper_bound;
using Base::find;
using Base::get_allocator;
using Base::key_comp;
@@ -3896,6 +3912,8 @@ namespace priv {
using Base::contains;
using Base::count;
using Base::equal_range;
using Base::lower_bound;
using Base::upper_bound;
using Base::find;
using Base::get_allocator;
using Base::key_comp;
@@ -3956,6 +3974,8 @@ namespace priv {
using Base::contains;
using Base::count;
using Base::equal_range;
using Base::lower_bound;
using Base::upper_bound;
using Base::find;
using Base::operator[];
using Base::get_allocator;
@@ -4013,6 +4033,8 @@ namespace priv {
using Base::contains;
using Base::count;
using Base::equal_range;
using Base::lower_bound;
using Base::upper_bound;
using Base::find;
using Base::get_allocator;
using Base::key_comp;