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 { ...@@ -705,7 +705,8 @@ class wBPTree {
auto d = depth.get_ro(); auto d = depth.get_ro();
while (d-- > 0) { while (d-- > 0) {
auto pos = lookupPositionInBranchNode(node.branch, key); 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; return node.leaf;
} }
......
...@@ -74,10 +74,8 @@ class wHBPTree { ...@@ -74,10 +74,8 @@ class wHBPTree {
struct Node { struct Node {
Node() : tag(BLANK) {}; Node() : tag(BLANK) {};
Node(pptr<LeafNode> leaf_) : tag(LEAF), leaf(leaf_) {}; explicit Node(pptr<LeafNode> leaf_) : tag(LEAF), leaf(leaf_) {};
explicit Node(BranchNode branch_) : tag(BRANCH), branch(branch_) {};
Node(BranchNode branch_) : tag(BRANCH), branch(branch_) {};
Node(const Node &other) { copy(other); }; Node(const Node &other) { copy(other); };
void copy(const Node &other) throw() { void copy(const Node &other) throw() {
...@@ -190,7 +188,11 @@ class wHBPTree { ...@@ -190,7 +188,11 @@ class wHBPTree {
return new BranchNode(); return new BranchNode();
} }
void deleteBranchNode(BranchNode*& node) { BranchNode *newBranchNode(const BranchNode *other) {
return new BranchNode(*other);
}
void deleteBranchNode(BranchNode *&node) {
delete node; delete node;
node = nullptr; node = nullptr;
} }
...@@ -383,7 +385,7 @@ class wHBPTree { ...@@ -383,7 +385,7 @@ class wHBPTree {
++leafs; ++leafs;
currentLeaf = currentLeaf->nextLeaf; 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"); assert(x == int(x) && "Not supported for this amount of leafs, yet");
/* actual recovery */ /* actual recovery */
...@@ -505,7 +507,7 @@ class wHBPTree { ...@@ -505,7 +507,7 @@ class wHBPTree {
auto &splitRef = *splitInfo; auto &splitRef = *splitInfo;
/// insert the new entry /// insert the new entry
if (slotPos-1 <= (M + 1) / 2) if (slotPos < (M + 1) / 2)
insertInLeafNodeAtPosition(splitRef.leftChild.leaf, slotPos, key, val); insertInLeafNodeAtPosition(splitRef.leftChild.leaf, slotPos, key, val);
else else
insertInLeafNodeAtPosition(splitRef.rightChild.leaf, insertInLeafNodeAtPosition(splitRef.rightChild.leaf,
...@@ -741,7 +743,7 @@ class wHBPTree { ...@@ -741,7 +743,7 @@ class wHBPTree {
auto d = depth; auto d = depth;
while (d-- > 0) { while (d-- > 0) {
auto pos = lookupPositionInBranchNode(node.branch, key); auto pos = lookupPositionInBranchNode(node.branch, key);
node = node.branch->children[pos]; node = node.branch->children[node.branch->search.slot[pos]];
} }
return node.leaf; return node.leaf;
} }
...@@ -810,7 +812,7 @@ class wHBPTree { ...@@ -810,7 +812,7 @@ class wHBPTree {
* @param key the key to be deleted * @param key the key to be deleted
* @return true if the entry was 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); assert(d >= 1);
bool deleted = false; bool deleted = false;
const auto &nodeRef = *node; const auto &nodeRef = *node;
...@@ -925,7 +927,7 @@ class wHBPTree { ...@@ -925,7 +927,7 @@ class wHBPTree {
* @param child the node at which the underflow occured * @param child the node at which the underflow occured
* @return the (possibly new) child node (in case of a merge) * @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) { BranchNode *child) {
assert(node != nullptr); assert(node != nullptr);
assert(child != nullptr); assert(child != nullptr);
......
...@@ -937,7 +937,7 @@ TEST_CASE("Finding the leaf node containing a key", "[wBPTree]") { ...@@ -937,7 +937,7 @@ TEST_CASE("Finding the leaf node containing a key", "[wBPTree]") {
nodeRef.search.get_rw().slot[0] = 1; nodeRef.search.get_rw().slot[0] = 1;
btree.rootNode = node; btree.rootNode = node;
btree.depth = 2; btree.depth = 1;
btree.insertInBranchNode(node, 1, 12, 112, &splitInfo); btree.insertInBranchNode(node, 1, 12, 112, &splitInfo);
REQUIRE(leaf2->search.get_ro().slot[0] == 2); 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