Add BtreeIteratorBase and move iterator increment/decrement slow paths to internal/btree.cc. Introduce BtreeIteratorBase so iterator slow paths operate on type-erased node pointers and children offsets, and implement BtreeIteratorIncrementSlow<FieldType> and BtreeIteratorDecrementSlow<FieldType> in internal/btree.cc instantiated for uint8_t and uint16_t. PiperOrigin-RevId: 1029771585
diff --git a/absl/container/btree_test.cc b/absl/container/btree_test.cc index 4404d08..2c6f8f3 100644 --- a/absl/container/btree_test.cc +++ b/absl/container/btree_test.cc
@@ -436,6 +436,11 @@ return Btree::params_type::template destroy_is_trivial< typename Btree::allocator_type>(); } + + template <typename Btree> + constexpr static const BtreeDtorPolicy* DtorPolicy() { + return &btree<typename Btree::params_type>::GetDtorPolicy(); + } }; namespace { @@ -504,6 +509,23 @@ EXPECT_FALSE((IsLinear<std::string, std::less<std::string>>())); } +TEST(Btree, DtorPolicySharing) { + // Matching slot layouts share a policy; trivial types omit the destructor. + EXPECT_TRUE(BtreeNodePeer::DtorPolicy<absl::btree_set<int64_t>>() == + (BtreeNodePeer::DtorPolicy< + absl::btree_multiset<int64_t, std::greater<int64_t>>>())); + EXPECT_TRUE(BtreeNodePeer::DtorPolicy<absl::btree_set<int64_t>>() == + BtreeNodePeer::DtorPolicy<absl::btree_set<double>>()); + EXPECT_TRUE((BtreeNodePeer::DtorPolicy<absl::btree_map<int32_t, int32_t>>() == + BtreeNodePeer::DtorPolicy<absl::btree_map<uint32_t, float>>())); + EXPECT_TRUE( + BtreeNodePeer::DtorPolicy<absl::btree_set<int64_t>>()->destroy_n == + nullptr); + EXPECT_TRUE( + BtreeNodePeer::DtorPolicy<absl::btree_set<std::string>>()->destroy_n != + nullptr); +} + TEST(Btree, BtreeMapCanHoldMoveOnlyTypes) { EXPECT_TRUE(BtreeNodePeer::DestroyIsTrivial<absl::btree_set<int>>()); EXPECT_FALSE(BtreeNodePeer::DestroyIsTrivial<absl::btree_set<std::string>>());
diff --git a/absl/container/internal/btree.cc b/absl/container/internal/btree.cc index 6faa3b7..2113eb0 100644 --- a/absl/container/internal/btree.cc +++ b/absl/container/internal/btree.cc
@@ -14,10 +14,15 @@ #include "absl/container/internal/btree.h" +#include <cassert> +#include <cstddef> #include <cstdint> +#include <memory> #include "absl/base/attributes.h" #include "absl/base/config.h" +#include "absl/base/optimization.h" +#include "absl/container/internal/container_memory.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -26,6 +31,224 @@ ABSL_CONST_INIT ABSL_DLL const BtreeEmptyNode<uint8_t> kBtreeEmptyNode8{}; ABSL_CONST_INIT ABSL_DLL const BtreeEmptyNode<uint16_t> kBtreeEmptyNode16{}; +namespace { + +// Returns the aligned byte size of a leaf node for the given slot count. +inline size_t LeafSize(const BtreeDtorPolicy& policy, size_t slot_count) { + return policy.LeafSize(slot_count); +} + +// Returns the byte size of an internal node. +inline size_t InternalSize(size_t children_offset, size_t node_slots) { + return children_offset + (node_slots + 1) * sizeof(void*); +} + +// Returns a pointer to the slot at the given index within node. +inline void* NodeSlot(void* node, size_t slots_offset, size_t slot_size, + size_t i) { + return static_cast<char*>(node) + slots_offset + i * slot_size; +} + +// Returns the slot capacity of a leaf or internal node. +template <typename FieldType> +FieldType NodeMaxCount(const btree_node_base<FieldType>* node, + uint16_t node_slots) { + return node->max_count(static_cast<FieldType>(node_slots)); +} + +// Null callback selects default pointer-aligned node deletion. +inline void DeallocateNodeWithFn(void* node, size_t size, + BtreeDeallocFn dealloc, void* alloc) { + SanitizerUnpoisonMemoryRegion(node, size); + if (ABSL_PREDICT_TRUE(dealloc == nullptr)) { + std::allocator<char> default_alloc; + Deallocate<alignof(void*)>(&default_alloc, node, size); + return; + } + dealloc(alloc, node, size); +} + +// Destroys all elements and frees every node in the subtree. +template <typename FieldType> +void ClearAndDeleteSubtree(btree_node_base<FieldType>* node, + const BtreeDtorPolicy& policy, + BtreeDeallocFn dealloc, void* alloc) { + assert(node->count() > 0); + const size_t slot_size = policy.slot_size; + const size_t slots_offset = policy.slots_offset; + const uint16_t node_slots = policy.node_slots; + const BtreeDestroyNFn destroy_n = policy.destroy_n; + + const auto destroy_node_slots = [&](btree_node_base<FieldType>* n) { + n->next_generation(); + const size_t count = n->count(); + if (count == 0) return; + void* slots = NodeSlot(n, slots_offset, slot_size, n->start()); + if (destroy_n != nullptr) { + destroy_n(alloc, slots, count); + } + SanitizerPoisonMemoryRegion(slots, count * slot_size); + }; + + if (node->is_leaf()) { + destroy_node_slots(node); + DeallocateNodeWithFn(node, LeafSize(policy, NodeMaxCount(node, node_slots)), + dealloc, alloc); + return; + } + + const size_t coff = policy.ComputeChildrenOffset(); + const size_t internal_size = InternalSize(coff, node_slots); + + btree_node_base<FieldType>* delete_root_parent = node->parent(); + + // Navigate to the leftmost leaf under node, and then delete upwards. + while (node->is_internal()) node = node->start_child(coff); + // When generations are enabled, we delete the leftmost leaf last in case it's + // the parent of the root and we need to check whether it's a leaf before we + // can update the root's generation. + btree_node_base<FieldType>* leftmost_leaf = node; + + // Use `size_t` because `pos` needs to be able to hold `kNodeSlots+1`, + // which isn't guaranteed to be a valid `FieldType`. + size_t pos = node->position(); + btree_node_base<FieldType>* parent = node->parent(); + for (;;) { + // In each iteration of the next loop, we delete one leaf node and go right. + assert(pos <= parent->finish()); + do { + node = parent->child(coff, pos); + if (node->is_internal()) { + // Navigate to the leftmost leaf under node. + while (node->is_internal()) node = node->start_child(coff); + pos = node->position(); + parent = node->parent(); + } + destroy_node_slots(node); + if (!BtreeGenerationsEnabled() || leftmost_leaf != node) { + DeallocateNodeWithFn(node, + LeafSize(policy, NodeMaxCount(node, node_slots)), + dealloc, alloc); + } + ++pos; + } while (pos <= parent->finish()); + + // Once we've deleted all children of parent, delete parent and go up/right. + assert(pos > parent->finish()); + do { + node = parent; + pos = node->position(); + parent = node->parent(); + destroy_node_slots(node); + DeallocateNodeWithFn(node, internal_size, dealloc, alloc); + if (parent == delete_root_parent) { + if constexpr (BtreeGenerationsEnabled()) { + DeallocateNodeWithFn( + leftmost_leaf, + LeafSize(policy, NodeMaxCount(leftmost_leaf, node_slots)), + dealloc, alloc); + } + return; + } + ++pos; + } while (pos > parent->finish()); + } +} + +} // namespace + +// Destroys all elements and frees every node using the default deallocator. +template <typename FieldType> +void BtreeDestroy(btree_node_base<FieldType>* root, + const BtreeDtorPolicy& policy) { + ClearAndDeleteSubtree(root, policy, nullptr, nullptr); +} + +// Destroys all elements and frees every node using a custom deallocator. +template <typename FieldType> +void BtreeDestroy(btree_node_base<FieldType>* root, + const BtreeDtorPolicy& policy, BtreeDeallocFn dealloc, + void* alloc) { + ClearAndDeleteSubtree(root, policy, dealloc, alloc); +} + +template void BtreeDestroy<uint8_t>(btree_node_base<uint8_t>*, + const BtreeDtorPolicy&); +template void BtreeDestroy<uint16_t>(btree_node_base<uint16_t>*, + const BtreeDtorPolicy&); +template void BtreeDestroy<uint8_t>(btree_node_base<uint8_t>*, + const BtreeDtorPolicy&, BtreeDeallocFn, + void*); +template void BtreeDestroy<uint16_t>(btree_node_base<uint16_t>*, + const BtreeDtorPolicy&, BtreeDeallocFn, + void*); + +// Advances an iterator past the end of a leaf or into an internal node's child. +template <typename FieldType> +BtreeIteratorBase BtreeIteratorIncrementSlow(BtreeIteratorBase it, + size_t children_offset) { + auto* node = it.node->as<FieldType>(); + int position = it.position; + if (node->is_leaf()) { + assert(position >= node->finish()); + while (position == node->finish() && !node->is_root()) { + assert(node->parent()->child(children_offset, node->position()) == node); + position = node->position(); + node = node->parent(); + } + // TODO(ezb): assert we aren't incrementing end() instead of handling. + if (position == node->finish()) { + return it; + } + } else { + assert(position < node->finish()); + node = node->child(children_offset, static_cast<size_t>(position + 1)); + while (node->is_internal()) { + node = node->start_child(children_offset); + } + position = node->start(); + } + return {node, position}; +} + +template BtreeIteratorBase BtreeIteratorIncrementSlow<uint8_t>( + BtreeIteratorBase, size_t); +template BtreeIteratorBase BtreeIteratorIncrementSlow<uint16_t>( + BtreeIteratorBase, size_t); + +// Moves an iterator before a leaf start or into an internal node's child. +template <typename FieldType> +BtreeIteratorBase BtreeIteratorDecrementSlow(BtreeIteratorBase it, + size_t children_offset) { + auto* node = it.node->as<FieldType>(); + int position = it.position; + if (node->is_leaf()) { + assert(position <= -1); + while (position < node->start() && !node->is_root()) { + assert(node->parent()->child(children_offset, node->position()) == node); + position = static_cast<int>(node->position()) - 1; + node = node->parent(); + } + // TODO(ezb): assert we aren't decrementing begin() instead of handling. + if (position < node->start()) { + return it; + } + } else { + assert(position >= node->start()); + node = node->child(children_offset, static_cast<size_t>(position)); + while (node->is_internal()) { + node = node->child(children_offset, node->finish()); + } + position = static_cast<int>(node->finish()) - 1; + } + return {node, position}; +} + +template BtreeIteratorBase BtreeIteratorDecrementSlow<uint8_t>( + BtreeIteratorBase, size_t); +template BtreeIteratorBase BtreeIteratorDecrementSlow<uint16_t>( + BtreeIteratorBase, size_t); + } // namespace container_internal ABSL_NAMESPACE_END } // namespace absl
diff --git a/absl/container/internal/btree.h b/absl/container/internal/btree.h index b169e6e..396b3c5 100644 --- a/absl/container/internal/btree.h +++ b/absl/container/internal/btree.h
@@ -54,6 +54,7 @@ #include <iterator> #include <limits> #include <memory> +#include <new> #include <string> #include <type_traits> #include <utility> @@ -1208,6 +1209,34 @@ return node_a == node_b; } +struct BtreeIteratorBase { + btree_node_header* node; + int position; + + friend bool operator==(BtreeIteratorBase a, BtreeIteratorBase b) { + return a.node == b.node && a.position == b.position; + } + friend bool operator!=(BtreeIteratorBase a, BtreeIteratorBase b) { + return !(a == b); + } +}; + +template <typename FieldType> +BtreeIteratorBase BtreeIteratorIncrementSlow(BtreeIteratorBase it, + size_t children_offset); +extern template BtreeIteratorBase BtreeIteratorIncrementSlow<uint8_t>( + BtreeIteratorBase, size_t); +extern template BtreeIteratorBase BtreeIteratorIncrementSlow<uint16_t>( + BtreeIteratorBase, size_t); + +template <typename FieldType> +BtreeIteratorBase BtreeIteratorDecrementSlow(BtreeIteratorBase it, + size_t children_offset); +extern template BtreeIteratorBase BtreeIteratorDecrementSlow<uint8_t>( + BtreeIteratorBase, size_t); +extern template BtreeIteratorBase BtreeIteratorDecrementSlow<uint16_t>( + BtreeIteratorBase, size_t); + class btree_iterator_generation_info_enabled { public: explicit btree_iterator_generation_info_enabled(uint32_t g) @@ -1432,6 +1461,10 @@ return true; } + BtreeIteratorBase raw() const { + return {const_cast<normal_node*>(node_), position_}; + } + // Returns n such that n calls to ++other yields *this. // Precondition: n exists && (this->node_ != other.node_ || // !this->node_->is_leaf() || this->position_ != other.position_). @@ -1440,22 +1473,26 @@ // Increment/decrement the iterator. void increment() { assert_valid_generation(node_); - if (node_->is_leaf() && ++position_ < node_->finish()) { + if (ABSL_PREDICT_TRUE(node_->is_leaf() && ++position_ < node_->finish())) { return; } - increment_slow(); + const BtreeIteratorBase res = BtreeIteratorIncrementSlow<field_type>( + raw(), node_type::kChildrenOffset); + node_ = static_cast<Node*>(res.node); + position_ = res.position; } - void increment_slow(); btree_iterator& increment_n_slow(difference_type n); void decrement() { assert_valid_generation(node_); - if (node_->is_leaf() && --position_ >= node_->start()) { + if (ABSL_PREDICT_TRUE(node_->is_leaf() && --position_ >= node_->start())) { return; } - decrement_slow(); + const BtreeIteratorBase res = BtreeIteratorDecrementSlow<field_type>( + raw(), node_type::kChildrenOffset); + node_ = static_cast<Node*>(res.node); + position_ = res.position; } - void decrement_slow(); btree_iterator& decrement_n_slow(difference_type n); const key_type& key() const { @@ -1521,6 +1558,97 @@ bool empty() const { return size == 0; } }; +using BtreeDestroyNFn = void (*)(void* alloc, void* slots, size_t count); +using BtreeDeallocFn = void (*)(void* alloc, void* node, size_t size); + +// Compact 16-byte policy for destroying or clearing a B-tree, kept separate +// from BtreePolicy so translation units that only destroy or clear a B-tree do +// not instantiate transfer or allocation callbacks. +struct BtreeDtorPolicy { + uint32_t slot_size; + uint16_t node_slots; + uint16_t slots_offset; + BtreeDestroyNFn destroy_n; + + static constexpr size_t LeafSize(uint16_t slots_offset, size_t slot_count, + uint32_t slot_size) { + const size_t raw = slots_offset + slot_count * slot_size; + return (raw + alignof(void*) - 1) & ~(alignof(void*) - 1); + } + + constexpr size_t LeafSize(size_t slot_count) const { + return LeafSize(slots_offset, slot_count, slot_size); + } + + static constexpr uint32_t ComputeChildrenOffset(uint16_t slots_offset, + uint16_t node_slots, + uint32_t slot_size) { + return static_cast<uint32_t>(LeafSize(slots_offset, node_slots, slot_size)); + } + + constexpr uint32_t ComputeChildrenOffset() const { + return ComputeChildrenOffset(slots_offset, node_slots, slot_size); + } +}; + +template <uint32_t kSlotSize, uint16_t kNodeSlots, uint16_t kSlotsOffset, + BtreeDestroyNFn kDestroyN> +inline constexpr BtreeDtorPolicy kBtreeDtor = { + kSlotSize, + kNodeSlots, + kSlotsOffset, + kDestroyN, +}; + +// Invokes fn with a typed allocator pointer or a temporary default allocator. +template <typename Alloc, typename Fn> +decltype(auto) WithBtreeAlloc(void* alloc, Fn&& fn) { + if constexpr (std::is_same_v<Alloc, std::allocator<char>>) { + (void)alloc; + std::allocator<char> a; + return fn(&a); + } else { + return fn(static_cast<Alloc*>(alloc)); + } +} + +template <size_t Alignment, typename Alloc> +void BtreeDeallocate(void* alloc, void* node, size_t size) { + WithBtreeAlloc<Alloc>(alloc, + [&](auto* a) { Deallocate<Alignment>(a, node, size); }); +} + +// Type-erased callback destroying a contiguous run of initialized slots. +template <typename SlotPolicy, typename Alloc> +void BtreeDestroyN(void* alloc, void* slots, size_t count) { + using Traits = common_policy_traits<SlotPolicy>; + auto* s = static_cast<typename SlotPolicy::slot_type*>(slots); + WithBtreeAlloc<Alloc>(alloc, [&](auto* a) { + for (size_t i = 0; i < count; ++i) { + Traits::destroy(a, std::launder(s + i)); + } + }); +} + +// Destroys all elements and frees every node in the subtree. +template <typename FieldType> +void BtreeDestroy(btree_node_base<FieldType>* root, + const BtreeDtorPolicy& policy); +template <typename FieldType> +void BtreeDestroy(btree_node_base<FieldType>* root, + const BtreeDtorPolicy& policy, BtreeDeallocFn dealloc, + void* alloc); +extern template void BtreeDestroy<uint8_t>(btree_node_base<uint8_t>*, + const BtreeDtorPolicy&); +extern template void BtreeDestroy<uint16_t>(btree_node_base<uint16_t>*, + const BtreeDtorPolicy&); +extern template void BtreeDestroy<uint8_t>(btree_node_base<uint8_t>*, + const BtreeDtorPolicy&, + BtreeDeallocFn, void*); +extern template void BtreeDestroy<uint16_t>(btree_node_base<uint16_t>*, + const BtreeDtorPolicy&, + BtreeDeallocFn, void*); + template <typename Params> class btree { using node_type = btree_node<Params>; @@ -1618,7 +1746,7 @@ // is complete. static_assert(static_assert_validation(), "This call must be elided."); if (!empty()) { - node_type::clear_and_delete(root(), mutable_allocator()); + destroy_subtree(root()); } } @@ -1843,7 +1971,46 @@ allocator_type get_allocator() const { return allocator(); } private: + friend class btree_node<Params>; friend struct btree_access; + friend class BtreeNodePeer; + + // Erase element type from default allocators to share policies and helpers. + static constexpr bool kIsDefaultAlloc = + std::is_same_v<allocator_type, std::allocator<value_type>>; + static constexpr bool kUsesDefaultNodeAlloc = + kIsDefaultAlloc && node_type::Alignment() <= alignof(void*); + using CanonicalAlloc = + std::conditional_t<kIsDefaultAlloc, std::allocator<char>, allocator_type>; + using SlotPolicy = typename Params::slot_policy; + + static constexpr BtreeDestroyNFn get_destroy_n_fn() { + if constexpr (params_type::template destroy_is_trivial<CanonicalAlloc>()) { + return nullptr; + } else { + return &BtreeDestroyN<SlotPolicy, CanonicalAlloc>; + } + } + + static constexpr BtreeDeallocFn get_dealloc_fn() { + return &BtreeDeallocate<node_type::Alignment(), CanonicalAlloc>; + } + + static constexpr const BtreeDtorPolicy& GetDtorPolicy() { + constexpr field_type kSlots = field_type{kNodeSlots}; + if constexpr (kNodeSlots <= (std::numeric_limits<field_type>::max)()) { + static_assert(BtreeDtorPolicy::ComputeChildrenOffset( + node_type::kSlotsOffset, kSlots, sizeof(slot_type)) == + node_type::kChildrenOffset); + } + return kBtreeDtor<sizeof(slot_type), kSlots, + static_cast<uint16_t>(node_type::kSlotsOffset), + get_destroy_n_fn()>; + } + + void destroy_subtree(node_type* node) { + node_type::clear_and_delete(node, mutable_allocator()); + } // Internal accessor routines. node_type* root() { return static_cast<node_type*>(common_.root); } @@ -2022,7 +2189,7 @@ const field_type to_erase, allocator_type* alloc) { value_destroy_n(i, to_erase, alloc); - if (is_internal()) { + if (ABSL_PREDICT_FALSE(is_internal())) { // Delete all children between begin and end. for (field_type j = 0; j < to_erase; ++j) { clear_and_delete(child(i + j + 1), alloc); @@ -2210,65 +2377,12 @@ template <typename P> void btree_node<P>::clear_and_delete(btree_node* node, allocator_type* alloc) { - assert(node->count() > 0); - if (node->is_leaf()) { - node->value_destroy_n(node->start(), node->count(), alloc); - deallocate(LeafSize(node->max_count()), node, alloc); - return; - } - - // The parent of the root of the subtree we are deleting. - btree_node* delete_root_parent = node->parent(); - - // Navigate to the leftmost leaf under node, and then delete upwards. - while (node->is_internal()) node = node->start_child(); -#ifdef ABSL_BTREE_ENABLE_GENERATIONS - // When generations are enabled, we delete the leftmost leaf last in case it's - // the parent of the root and we need to check whether it's a leaf before we - // can update the root's generation. - // TODO(ezb): if we change btree_node::is_root to check a bool inside the node - // instead of checking whether the parent is a leaf, we can remove this logic. - btree_node* leftmost_leaf = node; -#endif - // Use `size_type` because `pos` needs to be able to hold `kNodeSlots+1`, - // which isn't guaranteed to be a valid `field_type`. - size_type pos = node->position(); - btree_node* parent = node->parent(); - for (;;) { - // In each iteration of the next loop, we delete one leaf node and go right. - assert(pos <= parent->finish()); - do { - node = parent->child(static_cast<field_type>(pos)); - if (node->is_internal()) { - // Navigate to the leftmost leaf under node. - while (node->is_internal()) node = node->start_child(); - pos = node->position(); - parent = node->parent(); - } - node->value_destroy_n(node->start(), node->count(), alloc); -#ifdef ABSL_BTREE_ENABLE_GENERATIONS - if (leftmost_leaf != node) -#endif - deallocate(LeafSize(node->max_count()), node, alloc); - ++pos; - } while (pos <= parent->finish()); - - // Once we've deleted all children of parent, delete parent and go up/right. - assert(pos > parent->finish()); - do { - node = parent; - pos = node->position(); - parent = node->parent(); - node->value_destroy_n(node->start(), node->count(), alloc); - deallocate(InternalSize(), node, alloc); - if (parent == delete_root_parent) { -#ifdef ABSL_BTREE_ENABLE_GENERATIONS - deallocate(LeafSize(leftmost_leaf->max_count()), leftmost_leaf, alloc); -#endif - return; - } - ++pos; - } while (pos > parent->finish()); + if constexpr (btree<P>::kUsesDefaultNodeAlloc) { + (void)alloc; + BtreeDestroy<field_type>(node, btree<P>::GetDtorPolicy()); + } else { + BtreeDestroy<field_type>(node, btree<P>::GetDtorPolicy(), + btree<P>::get_dealloc_fn(), alloc); } } @@ -2333,58 +2447,6 @@ } template <typename N, typename R, typename P> -void btree_iterator<N, R, P>::increment_slow() { - N* node = node_; - int position = position_; - if (node->is_leaf()) { - assert(position >= node->finish()); - while (position == node->finish() && !node->is_root()) { - assert(node->parent()->child(node->position()) == node); - position = node->position(); - node = node->parent(); - } - // TODO(ezb): assert we aren't incrementing end() instead of handling. - if (position == node->finish()) { - return; - } - } else { - assert(position < node->finish()); - node = node->child(static_cast<field_type>(position + 1)); - while (node->is_internal()) { - node = node->start_child(); - } - position = node->start(); - } - *this = {node, position}; -} - -template <typename N, typename R, typename P> -void btree_iterator<N, R, P>::decrement_slow() { - N* node = node_; - int position = position_; - if (node->is_leaf()) { - assert(position <= -1); - while (position < node->start() && !node->is_root()) { - assert(node->parent()->child(node->position()) == node); - position = node->position() - 1; - node = node->parent(); - } - // TODO(ezb): assert we aren't decrementing begin() instead of handling. - if (position < node->start()) { - return; - } - } else { - assert(position >= node->start()); - node = node->child(static_cast<field_type>(position)); - while (node->is_internal()) { - node = node->child(node->finish()); - } - position = node->finish() - 1; - } - *this = {node, position}; -} - -template <typename N, typename R, typename P> btree_iterator<N, R, P>& btree_iterator<N, R, P>::increment_n_slow( difference_type n) { N* node = node_; @@ -2817,7 +2879,7 @@ return {0, begin}; } - if (static_cast<size_type>(count) == size()) { + if (ABSL_PREDICT_FALSE(static_cast<size_type>(count) == size())) { clear(); return {count, this->end()}; } @@ -2855,7 +2917,7 @@ template <typename P> void btree<P>::clear() { if (!empty()) { - node_type::clear_and_delete(root(), mutable_allocator()); + destroy_subtree(root()); } mutable_root() = mutable_rightmost() = EmptyNode(); mutable_size() = 0;