summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--searchlib/src/tests/common/bitvector/bitvector_test.cpp24
-rw-r--r--searchlib/src/vespa/searchlib/common/bitvector.cpp8
-rw-r--r--searchlib/src/vespa/searchlib/common/bitvector.h5
3 files changed, 18 insertions, 19 deletions
diff --git a/searchlib/src/tests/common/bitvector/bitvector_test.cpp b/searchlib/src/tests/common/bitvector/bitvector_test.cpp
index a0e46870741..499db526dbe 100644
--- a/searchlib/src/tests/common/bitvector/bitvector_test.cpp
+++ b/searchlib/src/tests/common/bitvector/bitvector_test.cpp
@@ -312,23 +312,23 @@ setEveryNthBit(uint32_t n, BitVector & bv, uint32_t offset, uint32_t end) {
bv.invalidateCachedCount();
}
BitVector::UP
-createEveryNthBitSet(uint32_t n, uint32_t end) {
- BitVector::UP bv(BitVector::create(0, end));
- setEveryNthBit(n, *bv, 0, end);
+createEveryNthBitSet(uint32_t n, uint32_t offset, uint32_t sz) {
+ BitVector::UP bv(BitVector::create(offset, offset + sz));
+ setEveryNthBit(n, *bv, offset, offset + sz);
return bv;
}
template<typename Func>
void
-verifyThatLongerWithShorterWorksAsZeroPadded(uint32_t sz1, uint32_t sz2, Func func) {
- BitVector::UP aLarger = createEveryNthBitSet(2, sz2);
+verifyThatLongerWithShorterWorksAsZeroPadded(uint32_t offset, uint32_t sz1, uint32_t sz2, Func func) {
+ BitVector::UP aLarger = createEveryNthBitSet(2, offset, sz2);
- BitVector::UP bSmall = createEveryNthBitSet(3, sz1);
- BitVector::UP bLarger = createEveryNthBitSet(3, sz2);
- bLarger->clearInterval(sz1, sz2);
+ BitVector::UP bSmall = createEveryNthBitSet(3, 0, offset + sz1);
+ BitVector::UP bLarger = createEveryNthBitSet(3, 0, offset + sz2);
+ bLarger->clearInterval(offset + sz1, offset + sz2);
EXPECT_EQUAL(bSmall->countTrueBits(), bLarger->countTrueBits());
- BitVector::UP aLarger2 = BitVector::create(*aLarger);
+ BitVector::UP aLarger2 = BitVector::create(*aLarger, aLarger->getStartIndex(), aLarger->size());
EXPECT_TRUE(*aLarger == *aLarger2);
func(*aLarger, *bLarger);
func(*aLarger2, *bSmall);
@@ -338,7 +338,7 @@ verifyThatLongerWithShorterWorksAsZeroPadded(uint32_t sz1, uint32_t sz2, Func fu
TEST("requireThatAndWorks") {
for (uint32_t offset(0); offset < 100; offset++) {
testAnd(offset);
- verifyThatLongerWithShorterWorksAsZeroPadded(offset+256, offset+256 + offset + 3,
+ verifyThatLongerWithShorterWorksAsZeroPadded(offset, offset+256, offset+256 + offset + 3,
[](BitVector & a, const BitVector & b) { a.andWith(b); });
}
}
@@ -346,7 +346,7 @@ TEST("requireThatAndWorks") {
TEST("requireThatOrWorks") {
for (uint32_t offset(0); offset < 100; offset++) {
testOr(offset);
- verifyThatLongerWithShorterWorksAsZeroPadded(offset+256, offset+256 + offset + 3,
+ verifyThatLongerWithShorterWorksAsZeroPadded(offset, offset+256, offset+256 + offset + 3,
[](BitVector & a, const BitVector & b) { a.orWith(b); });
}
}
@@ -355,7 +355,7 @@ TEST("requireThatOrWorks") {
TEST("requireThatAndNotWorks") {
for (uint32_t offset(0); offset < 100; offset++) {
testAndNot(offset);
- verifyThatLongerWithShorterWorksAsZeroPadded(offset+256, offset+256 + offset + 3,
+ verifyThatLongerWithShorterWorksAsZeroPadded(offset, offset+256, offset+256 + offset + 3,
[](BitVector & a, const BitVector & b) { a.andNotWith(b); });
}
}
diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp
index 07d0815a910..fc11f9ba032 100644
--- a/searchlib/src/vespa/searchlib/common/bitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp
@@ -25,7 +25,7 @@ void verifyInclusiveStart(const search::BitVector & a, const search::BitVector &
void verifyInclusiveStart(const search::BitVector & a, const search::BitVector & b)
{
if (a.getStartIndex() < b.getStartIndex()) {
- throw IllegalArgumentException(make_string("[%d, %d] is not contained in [%d, %d]",
+ 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);
}
@@ -132,7 +132,7 @@ BitVector::Index
BitVector::count() const
{
// Subtract by one to compensate for guard bit
- return countInterval(getStartIndex(), getEndIndex());
+ return countInterval(getStartIndex(), size());
}
BitVector::Index
@@ -351,8 +351,8 @@ BitVector::create(Index start, Index end)
BitVector::UP
BitVector::create(const BitVector & org, Index start, Index end)
{
- return (start == 0)
- ? create(end)
+ return ((start == 0) && (end == org.size()))
+ ? create(org)
: std::make_unique<PartialBitVector>(org, start, end);
}
diff --git a/searchlib/src/vespa/searchlib/common/bitvector.h b/searchlib/src/vespa/searchlib/common/bitvector.h
index 9671e41df24..0ddd9d001aa 100644
--- a/searchlib/src/vespa/searchlib/common/bitvector.h
+++ b/searchlib/src/vespa/searchlib/common/bitvector.h
@@ -56,7 +56,6 @@ public:
* @return The Index of the first valid bit of the bitvector.
*/
Index getStartIndex() const { return _startOffset; }
- Index getEndIndex() const { return getStartIndex() + size(); }
/**
* Get next bit set in the bitvector (inclusive start).
@@ -73,7 +72,7 @@ public:
}
/**
- * Iterate over all true bits in th einclusive range.
+ * Iterate over all true bits in the inclusive range.
*
* @param func callback
* @param start first bit
@@ -86,7 +85,7 @@ public:
}
/**
- * Iterate over all true bits in th einclusive range.
+ * Iterate over all true bits in the inclusive range.
*
* @param func callback
* @param start first bit