Use tree traversal to remove data tree.
This commit is contained in:
parent
e7268744c6
commit
cf38eb0eb3
@ -100,19 +100,6 @@ uint64_t DataNodeStore::virtualBlocksizeBytes() const {
|
|||||||
return _layout.blocksizeBytes();
|
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 {
|
DataNodeLayout DataNodeStore::layout() const {
|
||||||
return _layout;
|
return _layout;
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,6 @@ public:
|
|||||||
|
|
||||||
void remove(cpputils::unique_ref<DataNode> node);
|
void remove(cpputils::unique_ref<DataNode> node);
|
||||||
|
|
||||||
void removeSubtree(cpputils::unique_ref<DataNode> node);
|
|
||||||
|
|
||||||
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
|
//TODO Test blocksizeBytes/numBlocks/estimateSpaceForNumBlocksLeft
|
||||||
uint64_t virtualBlocksizeBytes() const;
|
uint64_t virtualBlocksizeBytes() const;
|
||||||
uint64_t numNodes() const;
|
uint64_t numNodes() const;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "DataTreeStore.h"
|
#include "DataTreeStore.h"
|
||||||
#include "../datanodestore/DataNodeStore.h"
|
|
||||||
#include "../datanodestore/DataLeafNode.h"
|
#include "../datanodestore/DataLeafNode.h"
|
||||||
#include "DataTree.h"
|
#include "DataTree.h"
|
||||||
|
|
||||||
@ -36,9 +35,9 @@ unique_ref<DataTree> DataTreeStore::createNewTree() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DataTreeStore::remove(unique_ref<DataTree> tree) {
|
void DataTreeStore::remove(unique_ref<DataTree> tree) {
|
||||||
auto root = tree->releaseRootNode();
|
// Remove all nodes except for the root, which will be a leaf.
|
||||||
cpputils::destruct(std::move(tree)); // Destruct tree
|
tree->resizeNumBytes(0);
|
||||||
_nodeStore->removeSubtree(std::move(root));
|
_nodeStore->remove(tree->releaseRootNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user