Skip to content

Commit

Permalink
* use the sanitize range and check in "andWith" also
Browse files Browse the repository at this point in the history
* verifyInclusiveStart is not needed now that we do range checks
* the unit tests could only work in "/home/balder"
  • Loading branch information
arnej27959 committed Jan 23, 2023
1 parent a69b9c3 commit 4b6f692
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
13 changes: 7 additions & 6 deletions searchlib/src/tests/common/bitvector/bitvector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,6 @@ TEST("requireThatSequentialOperationsOnPartialWorks")

PartialBitVector after(1000, 1100);
after.setInterval(1000, 1100);
EXPECT_EXCEPTION(p2.orWith(after), vespalib::IllegalArgumentException,
"IllegalArgumentException: [717, 919] starts before which is not allowed currently [1000, 1100] at "
"verifyInclusiveStart in /home/balder/git/vespa/searchlib/src/vespa/searchlib/common/bitvector.cpp:33");
EXPECT_EQUAL(202u, p2.countTrueBits());
}

Expand Down Expand Up @@ -365,9 +362,13 @@ verifyNonOverlappingWorksAsZeroPadded(bool clear, Func func) {
BitVector::UP right = createEveryNthBitSet(3, 2000, 100);
EXPECT_EQUAL(CNT, left->countTrueBits());
EXPECT_EQUAL(CNT, right->countTrueBits());
EXPECT_EXCEPTION(func(*left, *right), vespalib::IllegalArgumentException,
"IllegalArgumentException: [1000, 1100] starts before which is not allowed currently [2000, 2100] at "
"verifyInclusiveStart in /home/balder/git/vespa/searchlib/src/vespa/searchlib/common/bitvector.cpp:33");
func(*left, *right);
EXPECT_EQUAL(clear ? 0 : CNT, left->countTrueBits());
EXPECT_EQUAL(CNT, right->countTrueBits());
left = createEveryNthBitSet(3, 1000, 100);
right = createEveryNthBitSet(3, 2000, 100);
EXPECT_EQUAL(CNT, left->countTrueBits());
EXPECT_EQUAL(CNT, right->countTrueBits());
func(*right, *left);
EXPECT_EQUAL(CNT, left->countTrueBits());
EXPECT_EQUAL(clear ? 0 : CNT, right->countTrueBits());
Expand Down
19 changes: 5 additions & 14 deletions searchlib/src/vespa/searchlib/common/bitvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ using vespalib::alloc::Alloc;

namespace {

void verifyInclusiveStart(const search::BitVector & a, const search::BitVector & b) __attribute__((noinline));

void verifyInclusiveStart(const search::BitVector & a, const search::BitVector & b)
{
if (a.getStartIndex() < b.getStartIndex()) {
throw IllegalArgumentException(make_string("[%d, %d] starts before which is not allowed currently [%d, %d]",
a.getStartIndex(), a.size(), b.getStartIndex(), b.size()),
VESPA_STRLOC);
}
}

constexpr size_t MMAP_LIMIT = 256_Mi;

}
Expand Down Expand Up @@ -192,7 +181,6 @@ BitVector::countInterval(Range range_in) const
void
BitVector::orWith(const BitVector & right)
{
verifyInclusiveStart(*this, right);
Range range = sanitize(right.range());
if ( ! range.validNonZero()) return;

Expand Down Expand Up @@ -226,7 +214,11 @@ BitVector::repairEnds()
void
BitVector::andWith(const BitVector & right)
{
verifyInclusiveStart(*this, right);
Range range = sanitize(right.range());
if ( ! range.validNonZero()) {
clear();
return;
}

uint32_t commonBytes = std::min(getActiveBytes(), numActiveBytes(getStartIndex(), right.size()));
IAccelrated::getAccelerator().andBit(getActiveStart(), right.getWordIndex(getStartIndex()), commonBytes);
Expand All @@ -242,7 +234,6 @@ BitVector::andWith(const BitVector & right)
void
BitVector::andNotWith(const BitVector& right)
{
verifyInclusiveStart(*this, right);
Range range = sanitize(right.range());
if ( ! range.validNonZero()) return;

Expand Down
2 changes: 1 addition & 1 deletion searchlib/src/vespa/searchlib/common/partialbitvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace search {

/**
* search::PartialBitVector is a bitvector that is only represents 1 part
* of the full space. All operations concerning the whole vector while only
* of the full space. All operations concerning the whole vector will only
* be conducted on this smaller area.
*/
class PartialBitVector : public BitVector
Expand Down

0 comments on commit 4b6f692

Please sign in to comment.