Use tree traversal to remove data tree.

This commit is contained in:
Sebastian Messmer 2016-07-13 00:29:36 +02:00
parent e7268744c6
commit cf38eb0eb3
3 changed files with 3 additions and 19 deletions

View File

@ -100,19 +100,6 @@ uint64_t DataNodeStore::virtualBlocksizeBytes() const {
return _layout.blocksizeBytes();
}
void DataNodeStore::removeSubtree(unique_ref<DataNode> node) {
//TODO Make this faster by not loading the leaves but just deleting them. Can be recognized, because of the depth of their parents.
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(node.get());
if (inner != nullptr) {
for (uint32_t i = 0; i < inner->numChildren(); ++i) {
auto child = load(inner->getChild(i)->key());
ASSERT(child != none, "Couldn't load child node");
removeSubtree(std::move(*child));
}
}
remove(std::move(node));
}
DataNodeLayout DataNodeStore::layout() const {
return _layout;
}

View File

@ -39,8 +39,6 @@ public:
void remove(cpputils::unique_ref<DataNode> node);
void removeSubtree(cpputils::unique_ref<DataNode> node);
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
uint64_t virtualBlocksizeBytes() const;
uint64_t numNodes() const;

View File

@ -1,5 +1,4 @@
#include "DataTreeStore.h"
#include "../datanodestore/DataNodeStore.h"
#include "../datanodestore/DataLeafNode.h"
#include "DataTree.h"
@ -36,9 +35,9 @@ unique_ref<DataTree> DataTreeStore::createNewTree() {
}
void DataTreeStore::remove(unique_ref<DataTree> tree) {
auto root = tree->releaseRootNode();
cpputils::destruct(std::move(tree)); // Destruct tree
_nodeStore->removeSubtree(std::move(root));
// Remove all nodes except for the root, which will be a leaf.
tree->resizeNumBytes(0);
_nodeStore->remove(tree->releaseRootNode());
}
}