Commit 1265a114 authored by Philipp Götze's avatar Philipp Götze
Browse files

🐞 Fixed a bug for wBP/wHBP Trees +++ Refactored wHBPTreeTest

parent e9e6d95b
Pipeline #280 passed with stages
in 10 minutes and 2 seconds
......@@ -705,7 +705,8 @@ class wBPTree {
auto d = depth.get_ro();
while (d-- > 0) {
auto pos = lookupPositionInBranchNode(node.branch, key);
node = node.branch->children.get_ro()[pos];
auto &nodeRef = *node.branch;
node = nodeRef.children.get_ro()[nodeRef.search.get_ro().slot[pos]];
}
return node.leaf;
}
......
......@@ -74,10 +74,8 @@ class wHBPTree {
struct Node {
Node() : tag(BLANK) {};
Node(pptr<LeafNode> leaf_) : tag(LEAF), leaf(leaf_) {};
Node(BranchNode branch_) : tag(BRANCH), branch(branch_) {};
explicit Node(pptr<LeafNode> leaf_) : tag(LEAF), leaf(leaf_) {};
explicit Node(BranchNode branch_) : tag(BRANCH), branch(branch_) {};
Node(const Node &other) { copy(other); };
void copy(const Node &other) throw() {
......@@ -190,7 +188,11 @@ class wHBPTree {
return new BranchNode();
}
void deleteBranchNode(BranchNode*& node) {
BranchNode *newBranchNode(const BranchNode *other) {
return new BranchNode(*other);
}
void deleteBranchNode(BranchNode *&node) {
delete node;
node = nullptr;
}
......@@ -383,7 +385,7 @@ class wHBPTree {
++leafs;
currentLeaf = currentLeaf->nextLeaf;
}
float x = std::log(leafs)/std::log(N+1);
float x = std::log(leafs)/std::log1p(N);
assert(x == int(x) && "Not supported for this amount of leafs, yet");
/* actual recovery */
......@@ -505,7 +507,7 @@ class wHBPTree {
auto &splitRef = *splitInfo;
/// insert the new entry
if (slotPos-1 <= (M + 1) / 2)
if (slotPos < (M + 1) / 2)
insertInLeafNodeAtPosition(splitRef.leftChild.leaf, slotPos, key, val);
else
insertInLeafNodeAtPosition(splitRef.rightChild.leaf,
......@@ -741,7 +743,7 @@ class wHBPTree {
auto d = depth;
while (d-- > 0) {
auto pos = lookupPositionInBranchNode(node.branch, key);
node = node.branch->children[pos];
node = node.branch->children[node.branch->search.slot[pos]];
}
return node.leaf;
}
......@@ -810,7 +812,7 @@ class wHBPTree {
* @param key the key to be deleted
* @return true if the entry was deleted
*/
bool eraseFromBranchNode(BranchNode *node, unsigned int d, const KeyType &key) {
bool eraseFromBranchNode(BranchNode *const node, const unsigned int d, const KeyType &key) {
assert(d >= 1);
bool deleted = false;
const auto &nodeRef = *node;
......@@ -925,7 +927,7 @@ class wHBPTree {
* @param child the node at which the underflow occured
* @return the (possibly new) child node (in case of a merge)
*/
BranchNode *underflowAtBranchLevel(BranchNode *node, unsigned int pos,
BranchNode *underflowAtBranchLevel(BranchNode * const node, unsigned int pos,
BranchNode *child) {
assert(node != nullptr);
assert(child != nullptr);
......
......@@ -937,7 +937,7 @@ TEST_CASE("Finding the leaf node containing a key", "[wBPTree]") {
nodeRef.search.get_rw().slot[0] = 1;
btree.rootNode = node;
btree.depth = 2;
btree.depth = 1;
btree.insertInBranchNode(node, 1, 12, 112, &splitInfo);
REQUIRE(leaf2->search.get_ro().slot[0] == 2);
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment