// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "btreerootbase.h" #include namespace vespalib::btree { template BTreeRootBase::BTreeRootBase() : _root(BTreeNode::Ref()), _frozenRoot(BTreeNode::Ref().ref()) { } template BTreeRootBase:: BTreeRootBase(const BTreeRootBase &rhs) : _root(rhs._root), _frozenRoot(rhs._frozenRoot.load()) { } template BTreeRootBase::~BTreeRootBase() { assert(!_root.valid()); #if 0 assert(!_frozenRoot.valid()); #endif } template BTreeRootBase & BTreeRootBase:: operator=(const BTreeRootBase &rhs) { _root = rhs._root; _frozenRoot.store(rhs._frozenRoot.load(), std::memory_order_release); return *this; } template void BTreeRootBase:: freeze(NodeAllocatorType &allocator) { if (NodeAllocatorType::isValidRef(_root)) { if (allocator.isLeafRef(_root)) assert(allocator.mapLeafRef(_root)->getFrozen()); else assert(allocator.mapInternalRef(_root)->getFrozen()); } _frozenRoot.store(_root.ref(), std::memory_order_release); } template void BTreeRootBase:: recursiveDelete(BTreeNode::Ref node, NodeAllocatorType &allocator) { assert(allocator.isValidRef(node)); if (!allocator.isLeafRef(node)) { InternalNodeType * inode = allocator.mapInternalRef(node); for (size_t i = 0; i < inode->validSlots(); ++i) { recursiveDelete(inode->getChild(i), allocator); } allocator.holdNode(node, inode); } else { allocator.holdNode(node, allocator.mapLeafRef(node)); } } }