diff options
author | Abseil Team <absl-team@google.com> | 2020-10-27 14:08:57 -0700 |
---|---|---|
committer | vslashg <gfalcon@google.com> | 2020-10-27 17:14:47 -0400 |
commit | 962b067540f511070b7afa4cda465233b42b560a (patch) | |
tree | d2ceea66018cb6d8dab291df01b61c0d22f0755e /absl/container/internal/btree_container.h | |
parent | 5bf048b8425cc0a342e4647932de19e25ffd6ad7 (diff) | |
download | abseil-962b067540f511070b7afa4cda465233b42b560a.tar.gz abseil-962b067540f511070b7afa4cda465233b42b560a.tar.bz2 abseil-962b067540f511070b7afa4cda465233b42b560a.zip |
Export of internal Abseil changes
--
e5b45b15c19e85aaa33430ac2bd45fcc2e52dad5 by Greg Falcon <gfalcon@google.com>:
Add extra tests exercising ShiftLeft() at boundary conditions, to guard against logic errors in our memory bounds checking.
PiperOrigin-RevId: 339326030
--
cdfde78815ca016a57f90f53d08c3335bd355f30 by Evan Brown <ezb@google.com>:
Fix a bug in b-tree erase() and count() in which we weren't accounting for cases where the comparator is heterogeneous and has different equivalence classes for different lookup types.
Optimize equal_range to avoid comparisons when possible.
PiperOrigin-RevId: 339270230
--
b4aa337c156fa91f74f25c676c679ae146311968 by Derek Mauro <dmauro@google.com>:
Fix execution of the cmake build scripts when not on Kokoro
PiperOrigin-RevId: 339131253
--
fa3d1f602f711be72fde6b5f29d6341b9b5f8a2c by Derek Mauro <dmauro@google.com>:
Update Docker container used for Alpine Linux testing
PiperOrigin-RevId: 339074246
GitOrigin-RevId: e5b45b15c19e85aaa33430ac2bd45fcc2e52dad5
Change-Id: I2cc3adc4de3493203c8a944aedee40efa54af0c0
Diffstat (limited to 'absl/container/internal/btree_container.h')
-rw-r--r-- | absl/container/internal/btree_container.h | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/absl/container/internal/btree_container.h b/absl/container/internal/btree_container.h index 3792bc21..887eda41 100644 --- a/absl/container/internal/btree_container.h +++ b/absl/container/internal/btree_container.h @@ -104,6 +104,11 @@ class btree_container { // 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); } @@ -152,6 +157,11 @@ class btree_container { iterator erase(const_iterator first, const_iterator last) { return tree_.erase_range(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; + } // Extract routines. node_type extract(iterator position) { @@ -270,12 +280,6 @@ class btree_set_container : public btree_container<Tree> { 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 { - return this->tree_.count_unique(key); - } - // Insertion routines. std::pair<iterator, bool> insert(const value_type &v) { return this->tree_.insert_unique(params_type::key(v), v); @@ -333,16 +337,10 @@ class btree_set_container : public btree_container<Tree> { return res.first; } - // Deletion routines. - // TODO(ezb): we should support heterogeneous comparators that have different - // behavior for K!=key_type. - template <typename K = key_type> - size_type erase(const key_arg<K> &key) { - return this->tree_.erase_unique(key); - } - using super_type::erase; - // Node extraction routines. + // TODO(ezb): when the comparator is heterogeneous and has different + // equivalence classes for different lookup types, we should extract the first + // equivalent value if there are multiple. template <typename K = key_type> node_type extract(const key_arg<K> &key) { auto it = this->find(key); @@ -578,12 +576,6 @@ class btree_multiset_container : public btree_container<Tree> { const allocator_type &alloc) : btree_multiset_container(init.begin(), init.end(), alloc) {} - // Lookup routines. - template <typename K = key_type> - size_type count(const key_arg<K> &key) const { - return this->tree_.count_multi(key); - } - // Insertion routines. iterator insert(const value_type &v) { return this->tree_.insert_multi(v); } iterator insert(value_type &&v) { @@ -628,14 +620,9 @@ class btree_multiset_container : public btree_container<Tree> { return res; } - // Deletion routines. - template <typename K = key_type> - size_type erase(const key_arg<K> &key) { - return this->tree_.erase_multi(key); - } - using super_type::erase; - // Node extraction routines. + // TODO(ezb): we are supposed to extract the first equivalent key if there are + // multiple, but this isn't guaranteed to extract the first one. template <typename K = key_type> node_type extract(const key_arg<K> &key) { auto it = this->find(key); |