diff --git a/src/util/JoinAlgorithms/JoinAlgorithms.h b/src/util/JoinAlgorithms/JoinAlgorithms.h index ac20b0d7e3..dd73749849 100644 --- a/src/util/JoinAlgorithms/JoinAlgorithms.h +++ b/src/util/JoinAlgorithms/JoinAlgorithms.h @@ -565,10 +565,6 @@ class BlockAndSubrange { subrange_{0, block_->size()} {} // Return a reference to the last element of the currently specified subrange. - reference back() { - AD_CORRECTNESS_CHECK(!empty() && subrange_.second <= block_->size()); - return (*block_)[subrange_.second - 1]; - } const_reference back() const { AD_CORRECTNESS_CHECK(!empty() && subrange_.second <= block_->size()); return std::as_const(*block_)[subrange_.second - 1]; @@ -826,9 +822,9 @@ struct BlockZipperJoinImpl { // the last one, which might contain elements `> currentEl` at the end. auto getEqualToCurrentEl(const auto& blocks, const auto& currentEl) { auto result = blocks; - // If one of the inputs is empty, this function shouldn't have been called - // in the first place. - AD_CORRECTNESS_CHECK(!result.empty()); + if (result.empty()) { + return result; + } auto& last = result.back(); last.setSubrange( std::ranges::equal_range(last.subrange(), currentEl, lessThan_)); @@ -973,19 +969,16 @@ struct BlockZipperJoinImpl { while (!equalToCurrentElLeft.empty() && !equalToCurrentElRight.empty()) { addAll(equalToCurrentElLeft, equalToCurrentElRight); switch (blockStatus.value()) { - case BlockStatus::allFilled: { + case BlockStatus::allFilled: removeEqualToCurrentEl(sameBlocksLeft, currentEl); removeEqualToCurrentEl(sameBlocksRight, currentEl); return; - } - case BlockStatus::rightMissing: { + case BlockStatus::rightMissing: getNextBlocks(equalToCurrentElRight, rightSide_); continue; - } - case BlockStatus::leftMissing: { + case BlockStatus::leftMissing: getNextBlocks(equalToCurrentElLeft, leftSide_); continue; - } default: AD_FAIL(); } diff --git a/test/JoinAlgorithmsTest.cpp b/test/JoinAlgorithmsTest.cpp index afacb70fca..0ef27278a5 100644 --- a/test/JoinAlgorithmsTest.cpp +++ b/test/JoinAlgorithmsTest.cpp @@ -172,6 +172,16 @@ TEST(JoinAlgorithms, JoinWithBlocksMoreThanThreeBlocksPerElement) { testJoin(a, b, expectedResult); } +// Test the coverage of a corner case. +TEST(JoinAlgorithms, JoinWithBlocksExactlyFourBlocksPerElement) { + NestedBlock a{{{42, 0}}, {{42, 1}}, {{42, 2}}, {{42, 3}}, + {}, {{48, 5}, {67, 0}}, {{96, 32}}, {{96, 33}}}; + NestedBlock b{{{42, 12}, {67, 13}}}; + JoinResult expectedResult{ + {42, 0, 12}, {42, 1, 12}, {42, 2, 12}, {42, 3, 12}, {67, 0, 13}}; + testJoin(a, b, expectedResult); +} + // ________________________________________________________________________________________ TEST(JoinAlgorithms, JoinWithBlocksMultipleBlocksPerElementBothSides) { NestedBlock a{{{42, 0}}, {{42, 1}, {42, 2}}, {{42, 3}, {67, 0}}};