Refactoring

This commit is contained in:
Sebastian Messmer 2015-02-24 23:11:20 +01:00
parent a71f26d0d4
commit 9d9c090148
2 changed files with 2 additions and 23 deletions

View File

@ -52,29 +52,11 @@ void DataTree::ifRootHasOnlyOneChildReplaceRootWithItsChild() {
} }
void DataTree::deleteLastChildSubtree(DataInnerNode *node) { void DataTree::deleteLastChildSubtree(DataInnerNode *node) {
deleteSubtree(node->LastChild()->key()); auto lastChild = _nodeStore->load(node->LastChild()->key());
_nodeStore->removeSubtree(std::move(lastChild));
node->removeLastChild(); node->removeLastChild();
} }
void DataTree::deleteSubtree(const Key &key) {
auto node = _nodeStore->load(key);
deleteChildrenOf(*node);
_nodeStore->remove(std::move(node));
}
void DataTree::deleteChildrenOf(const DataNode &node) {
const DataInnerNode *node_inner = dynamic_cast<const DataInnerNode*>(&node);
if (node_inner != nullptr) {
deleteChildrenOf(*node_inner);
}
}
void DataTree::deleteChildrenOf(const DataInnerNode &node) {
for(int i = 0; i < node.numChildren(); ++i) {
deleteSubtree(node.getChild(i)->key());
}
}
unique_ptr<DataLeafNode> DataTree::addDataLeaf() { unique_ptr<DataLeafNode> DataTree::addDataLeaf() {
auto insertPosOrNull = algorithms::GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(_nodeStore, _rootNode.get()); auto insertPosOrNull = algorithms::GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(_nodeStore, _rootNode.get());
if (insertPosOrNull) { if (insertPosOrNull) {

View File

@ -43,9 +43,6 @@ private:
std::unique_ptr<datanodestore::DataLeafNode> addDataLeafToFullTree(); std::unique_ptr<datanodestore::DataLeafNode> addDataLeafToFullTree();
void deleteLastChildSubtree(datanodestore::DataInnerNode *node); void deleteLastChildSubtree(datanodestore::DataInnerNode *node);
void deleteSubtree(const blockstore::Key &key);
void deleteChildrenOf(const datanodestore::DataNode &node);
void deleteChildrenOf(const datanodestore::DataInnerNode &node);
void ifRootHasOnlyOneChildReplaceRootWithItsChild(); void ifRootHasOnlyOneChildReplaceRootWithItsChild();
DISALLOW_COPY_AND_ASSIGN(DataTree); DISALLOW_COPY_AND_ASSIGN(DataTree);