From 64c95230cab145d12a367ce7da8e5f0e25eba569 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Sat, 17 Dec 2022 18:41:58 +0100 Subject: [PATCH] Delete dead code --- src/blobstore/CMakeLists.txt | 1 - .../onblocks/datatreestore/DataTree.cpp | 2 - .../datatreestore/impl/algorithms.cpp | 69 ---------- .../onblocks/datatreestore/impl/algorithms.h | 30 ----- test/blobstore/CMakeLists.txt | 2 - ...derNodeWithLessThanKChildrenOrNullTest.cpp | 87 ------------- ...rderNodeWithMoreThanOneChildOrNullTest.cpp | 119 ------------------ 7 files changed, 310 deletions(-) delete mode 100644 src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp delete mode 100644 src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.h delete mode 100644 test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp delete mode 100644 test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp diff --git a/src/blobstore/CMakeLists.txt b/src/blobstore/CMakeLists.txt index aaa42ccb..07cccf91 100644 --- a/src/blobstore/CMakeLists.txt +++ b/src/blobstore/CMakeLists.txt @@ -10,7 +10,6 @@ set(SOURCES implementations/onblocks/datanodestore/DataLeafNode.cpp implementations/onblocks/datanodestore/DataInnerNode.cpp implementations/onblocks/datanodestore/DataNodeStore.cpp - implementations/onblocks/datatreestore/impl/algorithms.cpp implementations/onblocks/datatreestore/impl/CachedValue.cpp implementations/onblocks/datatreestore/impl/LeafTraverser.cpp implementations/onblocks/datatreestore/LeafHandle.cpp diff --git a/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp b/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp index 5d85052d..43e7d7fb 100644 --- a/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp +++ b/src/blobstore/implementations/onblocks/datatreestore/DataTree.cpp @@ -5,8 +5,6 @@ #include "../datanodestore/DataLeafNode.h" #include "../utils/Math.h" -#include "impl/algorithms.h" - #include #include #include diff --git a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp b/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp deleted file mode 100644 index 9445a481..00000000 --- a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "algorithms.h" -#include -#include - -#include "../../datanodestore/DataInnerNode.h" -#include "../../datanodestore/DataNodeStore.h" -#include - -using std::function; -using cpputils::optional_ownership_ptr; -using cpputils::dynamic_pointer_move; -using cpputils::unique_ref; -using blobstore::onblocks::datanodestore::DataInnerNode; -using blobstore::onblocks::datanodestore::DataNode; -using blobstore::onblocks::datanodestore::DataNodeStore; -using blockstore::BlockId; -using boost::optional; -using boost::none; - -namespace blobstore { -namespace onblocks { -namespace datatreestore { -namespace algorithms { - -optional> getLastChildAsInnerNode(DataNodeStore *nodeStore, const DataInnerNode &node) { - BlockId blockId = node.readLastChild().blockId(); - auto lastChild = nodeStore->load(blockId); - ASSERT(lastChild != none, "Couldn't load last child"); - return dynamic_pointer_move(*lastChild); -} - -//Returns the lowest right border node meeting the condition specified (exclusive the leaf). -//Returns nullptr, if no inner right border node meets the condition. -optional_ownership_ptr GetLowestInnerRightBorderNodeWithConditionOrNull(DataNodeStore *nodeStore, datanodestore::DataNode *rootNode, function condition) { - optional_ownership_ptr currentNode = cpputils::WithoutOwnership(dynamic_cast(rootNode)); - optional_ownership_ptr result = cpputils::null(); - for (unsigned int i=0; i < rootNode->depth(); ++i) { - //TODO This unnecessarily loads the leaf node in the last loop run - auto lastChild = getLastChildAsInnerNode(nodeStore, *currentNode); - if (condition(*currentNode)) { - result = std::move(currentNode); - } - if (lastChild == none) { - // lastChild is a leaf - ASSERT(static_cast(i) == rootNode->depth()-1, "Couldn't get last child as inner node but we're not deep enough yet for the last child to be a leaf"); - break; - } - currentNode = cpputils::WithOwnership(std::move(*lastChild)); - } - - return result; -} - -optional_ownership_ptr GetLowestRightBorderNodeWithMoreThanOneChildOrNull(DataNodeStore *nodeStore, DataNode *rootNode) { - return GetLowestInnerRightBorderNodeWithConditionOrNull(nodeStore, rootNode, [] (const datanodestore::DataInnerNode &node) { - return node.numChildren() > 1; - }); -} - -optional_ownership_ptr GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(datanodestore::DataNodeStore *nodeStore, datanodestore::DataNode *rootNode) { - return GetLowestInnerRightBorderNodeWithConditionOrNull(nodeStore, rootNode, [] (const datanodestore::DataInnerNode &node) { - return node.numChildren() < node.maxStoreableChildren(); - }); -} - -} -} -} -} diff --git a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.h b/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.h deleted file mode 100644 index a04168a8..00000000 --- a/src/blobstore/implementations/onblocks/datatreestore/impl/algorithms.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#ifndef MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_DATATREESTORE_IMPL_ALGORITHMS_H_ -#define MESSMER_BLOBSTORE_IMPLEMENTATIONS_ONBLOCKS_DATATREESTORE_IMPL_ALGORITHMS_H_ - -#include - -namespace blobstore { -namespace onblocks { -namespace datanodestore{ -class DataNode; -class DataInnerNode; -class DataNodeStore; -} -namespace datatreestore { -namespace algorithms { - -//Returns the lowest right border node with at least two children. -//Returns nullptr, if all right border nodes have only one child (since the root is a right border node, this means that the whole tree has exactly one leaf) -cpputils::optional_ownership_ptr GetLowestRightBorderNodeWithMoreThanOneChildOrNull(datanodestore::DataNodeStore *nodeStore, datanodestore::DataNode *rootNode); - -//Returns the lowest right border node with less than k children (not considering leaves). -//Returns nullptr, if all right border nodes have k children (the tree is full) -cpputils::optional_ownership_ptr GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(datanodestore::DataNodeStore *nodeStore, datanodestore::DataNode *rootNode); - -} -} -} -} - -#endif diff --git a/test/blobstore/CMakeLists.txt b/test/blobstore/CMakeLists.txt index 05e98b8d..ce828a60 100644 --- a/test/blobstore/CMakeLists.txt +++ b/test/blobstore/CMakeLists.txt @@ -12,8 +12,6 @@ set(SOURCES implementations/onblocks/datanodestore/DataNodeViewTest.cpp implementations/onblocks/datanodestore/DataNodeStoreTest.cpp implementations/onblocks/datatreestore/testutils/DataTreeTest.cpp - implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp - implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp implementations/onblocks/datatreestore/DataTreeTest_Performance.cpp implementations/onblocks/datatreestore/DataTreeTest_ResizeByTraversing.cpp implementations/onblocks/datatreestore/DataTreeTest_NumStoredBytes.cpp diff --git a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp b/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp deleted file mode 100644 index 69a9ecd9..00000000 --- a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include - -#include "../testutils/DataTreeTest.h" -#include "blobstore/implementations/onblocks/datatreestore/DataTree.h" -#include "blobstore/implementations/onblocks/datanodestore/DataLeafNode.h" -#include "blobstore/implementations/onblocks/datanodestore/DataInnerNode.h" -#include -#include "blobstore/implementations/onblocks/datatreestore/impl/algorithms.h" - - -using blockstore::BlockId; -using cpputils::Data; -using namespace blobstore::onblocks::datatreestore::algorithms; - -class GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest: public DataTreeTest { -public: - struct TestData { - BlockId rootNode; - BlockId expectedResult; - }; - - void check(const TestData &testData) { - auto root = nodeStore->load(testData.rootNode).value(); - auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, root.get()); - EXPECT_EQ(testData.expectedResult, result->blockId()); - } - - TestData CreateTwoRightBorderNodes() { - auto node = CreateInner({CreateLeaf()}); - return TestData{node->blockId(), node->blockId()}; - } - - TestData CreateThreeRightBorderNodes() { - auto node = CreateInner({CreateLeaf()}); - auto root = CreateInner({node.get()}); - return TestData{root->blockId(), node->blockId()}; - } - - TestData CreateThreeRightBorderNodes_LastFull() { - auto root = CreateInner({CreateFullTwoLevel()}); - return TestData{root->blockId(), root->blockId()}; - } - - TestData CreateLargerTree() { - auto node = CreateInner({CreateLeaf(), CreateLeaf()}); - auto root = CreateInner({CreateFullTwoLevel().get(), node.get()}); - return TestData{root->blockId(), node->blockId()}; - } -}; - -TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, Leaf) { - auto leaf = nodeStore->createNewLeafNode(Data(0)); - auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, leaf.get()); - EXPECT_EQ(nullptr, result.get()); -} - -TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, TwoRightBorderNodes) { - auto testData = CreateTwoRightBorderNodes(); - check(testData); -} - -TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, ThreeRightBorderNodes) { - auto testData = CreateThreeRightBorderNodes(); - check(testData); -} - -TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, ThreeRightBorderNodes_LastFull) { - auto testData = CreateThreeRightBorderNodes_LastFull(); - check(testData); -} - -TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, LargerTree) { - auto testData = CreateLargerTree(); - check(testData); -} - -TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, FullTwoLevelTree) { - auto root = CreateFullTwoLevel(); - auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, root.get()); - EXPECT_EQ(nullptr, result.get()); -} - -TEST_F(GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNullTest, FullThreeLevelTree) { - auto root = CreateFullThreeLevel(); - auto result = GetLowestInnerRightBorderNodeWithLessThanKChildrenOrNull(nodeStore, root.get()); - EXPECT_EQ(nullptr, result.get()); -} diff --git a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp b/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp deleted file mode 100644 index fe6d8747..00000000 --- a/test/blobstore/implementations/onblocks/datatreestore/impl/GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include - -#include "../testutils/DataTreeTest.h" -#include "blobstore/implementations/onblocks/datatreestore/DataTree.h" -#include "blobstore/implementations/onblocks/datanodestore/DataLeafNode.h" -#include "blobstore/implementations/onblocks/datanodestore/DataInnerNode.h" -#include -#include "blobstore/implementations/onblocks/datatreestore/impl/algorithms.h" - - -using blockstore::BlockId; -using namespace blobstore::onblocks::datatreestore::algorithms; - -class GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest: public DataTreeTest { -public: - struct TestData { - BlockId rootNode; - BlockId expectedResult; - }; - - void check(const TestData &testData) { - auto root = nodeStore->load(testData.rootNode).value(); - auto result = GetLowestRightBorderNodeWithMoreThanOneChildOrNull(nodeStore, root.get()); - EXPECT_EQ(testData.expectedResult, result->blockId()); - } - - BlockId CreateLeafOnlyTree() { - return CreateLeaf()->blockId(); - } - - BlockId CreateTwoRightBorderNodes() { - return CreateInner({CreateLeaf()})->blockId(); - } - - BlockId CreateThreeRightBorderNodes() { - return CreateInner({CreateInner({CreateLeaf()})})->blockId(); - } - - TestData CreateThreeRightBorderNodes_LastFull() { - auto node = CreateFullTwoLevel(); - auto root = CreateInner({node.get()}); - return TestData{root->blockId(), node->blockId()}; - } - - TestData CreateLargerTree() { - auto node = CreateInner({CreateLeaf(), CreateLeaf()}); - auto root = CreateInner({CreateFullTwoLevel().get(), node.get()}); - return TestData{root->blockId(), node->blockId()}; - } - - TestData CreateThreeLevelTreeWithRightBorderSingleNodeChain() { - auto root = CreateInner({CreateFullTwoLevel(), CreateInner({CreateLeaf()})}); - return TestData{root->blockId(), root->blockId()}; - } - - TestData CreateThreeLevelTree() { - auto node = CreateInner({CreateLeaf(), CreateLeaf()}); - auto root = CreateInner({CreateFullTwoLevel().get(), node.get()}); - return TestData{root->blockId(), node->blockId()}; - } - - TestData CreateFullTwoLevelTree() { - auto node = CreateFullTwoLevel(); - return TestData{node->blockId(), node->blockId()}; - } - - TestData CreateFullThreeLevelTree() { - auto root = CreateFullThreeLevel(); - return TestData{root->blockId(), root->readLastChild().blockId()}; - } -}; - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, Leaf) { - auto leaf = nodeStore->load(CreateLeafOnlyTree()).value(); - auto result = GetLowestRightBorderNodeWithMoreThanOneChildOrNull(nodeStore, leaf.get()); - EXPECT_EQ(nullptr, result.get()); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, TwoRightBorderNodes) { - auto node = nodeStore->load(CreateTwoRightBorderNodes()).value(); - auto result = GetLowestRightBorderNodeWithMoreThanOneChildOrNull(nodeStore, node.get()); - EXPECT_EQ(nullptr, result.get()); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, ThreeRightBorderNodes) { - auto node = nodeStore->load(CreateThreeRightBorderNodes()).value(); - auto result = GetLowestRightBorderNodeWithMoreThanOneChildOrNull(nodeStore, node.get()); - EXPECT_EQ(nullptr, result.get()); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, ThreeRightBorderNodes_LastFull) { - auto testData = CreateThreeRightBorderNodes_LastFull(); - check(testData); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, LargerTree) { - auto testData = CreateLargerTree(); - check(testData); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, FullTwoLevelTree) { - auto testData = CreateFullTwoLevelTree(); - check(testData); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, FullThreeLevelTree) { - auto testData = CreateFullThreeLevelTree(); - check(testData); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, ThreeLevelTreeWithRightBorderSingleNodeChain) { - auto testData = CreateThreeLevelTreeWithRightBorderSingleNodeChain(); - check(testData); -} - -TEST_F(GetLowestRightBorderNodeWithMoreThanOneChildOrNullTest, ThreeLevelTree) { - auto testData = CreateThreeLevelTree(); - check(testData); -}