Skip to content

Commit

Permalink
chore: tidy btree related code
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason committed Aug 27, 2024
1 parent 553012d commit 5d10f26
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 330 deletions.
12 changes: 6 additions & 6 deletions include/leanstore/btree/core/BTreeGeneric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class BTreeGeneric : public leanstore::storage::BufferManagedTree {
inline void BTreeGeneric::freeBTreeNodesRecursive(BTreeGeneric& btree,
GuardedBufferFrame<BTreeNode>& guardedNode) {
if (!guardedNode->mIsLeaf) {
for (auto i = 0u; i <= guardedNode->mNumSeps; ++i) {
for (auto i = 0u; i <= guardedNode->mNumSlots; ++i) {
auto* childSwip = guardedNode->ChildSwipIncludingRightMost(i);
GuardedBufferFrame<BTreeNode> guardedChild(btree.mStore->mBufferManager.get(), guardedNode,
*childSwip);
Expand All @@ -230,7 +230,7 @@ inline void BTreeGeneric::IterateChildSwips(BufferFrame& bf, std::function<bool(
if (btreeNode.mIsLeaf) {
return;
}
for (uint16_t i = 0; i < btreeNode.mNumSeps; i++) {
for (uint16_t i = 0; i < btreeNode.mNumSlots; i++) {
if (!callback(*btreeNode.ChildSwip(i))) {
return;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ inline void BTreeGeneric::Checkpoint(BufferFrame& bf, void* dest) {

if (!destNode->mIsLeaf) {
// Replace all child swip to their page ID
for (uint64_t i = 0; i < destNode->mNumSeps; i++) {
for (uint64_t i = 0; i < destNode->mNumSlots; i++) {
if (!destNode->ChildSwip(i)->IsEvicted()) {
auto& childBf = destNode->ChildSwip(i)->AsBufferFrameMasked();
destNode->ChildSwip(i)->Evict(childBf.mHeader.mPageId);
Expand Down Expand Up @@ -349,17 +349,17 @@ inline ParentSwipHandler BTreeGeneric::FindParent(BTreeGeneric& btree, BufferFra
}

auto& nodeToFind = *reinterpret_cast<BTreeNode*>(bfToFind.mPage.mPayload);
const auto isInfinity = nodeToFind.mUpperFence.mOffset == 0;
const auto isInfinity = nodeToFind.mUpperFence.IsInfinity();
const auto keyToFind = nodeToFind.GetUpperFence();

auto posInParent = std::numeric_limits<uint32_t>::max();
auto searchCondition = [&](GuardedBufferFrame<BTreeNode>& guardedNode) {
if (isInfinity) {
childSwip = &(guardedNode->mRightMostChildSwip);
posInParent = guardedNode->mNumSeps;
posInParent = guardedNode->mNumSlots;
} else {
posInParent = guardedNode->LowerBound<false>(keyToFind);
if (posInParent == guardedNode->mNumSeps) {
if (posInParent == guardedNode->mNumSlots) {
childSwip = &(guardedNode->mRightMostChildSwip);
} else {
childSwip = guardedNode->ChildSwip(posInParent);
Expand Down
Loading

0 comments on commit 5d10f26

Please sign in to comment.