aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2022-05-09 17:00:05 +0200
committerGitHub <noreply@github.com>2022-05-09 17:00:05 +0200
commit6cbbe5aa211a3406ad56990029b857b96192e8a9 (patch)
tree83b02b2ade02a4409b58e20dddeeb71fe2b6075d
parenta54a876d65a13de9042b2c993a252bc43b8a9e88 (diff)
parent208a7c1db7a7a67aa71fae59ca0cd5615b688b6e (diff)
Merge pull request #22516 from vespa-engine/havardpe/move-functions-to-appropriate-classes
move functions to more appropriate classes
-rw-r--r--searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.cpp4
-rw-r--r--searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/attribute/flagattribute.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/attribute/flagattribute.h9
-rw-r--r--searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp30
-rw-r--r--searchlib/src/vespa/searchlib/common/allocatedbitvector.h8
-rw-r--r--searchlib/src/vespa/searchlib/common/bitvector.cpp21
-rw-r--r--searchlib/src/vespa/searchlib/common/bitvector.h11
-rw-r--r--searchlib/src/vespa/searchlib/common/growablebitvector.cpp27
-rw-r--r--searchlib/src/vespa/searchlib/common/growablebitvector.h2
10 files changed, 55 insertions, 77 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.cpp b/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.cpp
index a3a180a74df..3aecbc3ca0d 100644
--- a/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.cpp
+++ b/searchcore/src/vespa/searchcore/proton/feedoperation/lidvectorcontext.cpp
@@ -2,6 +2,7 @@
#include "lidvectorcontext.h"
#include <vespa/searchlib/common/bitvector.h>
+#include <vespa/searchlib/common/allocatedbitvector.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <cassert>
@@ -9,6 +10,7 @@
LOG_SETUP(".proton.feedoperation.lidvectorcontext");
using search::BitVector;
+using search::AllocatedBitVector;
namespace proton {
@@ -73,7 +75,7 @@ LidVectorContext::deserialize(vespalib::nbostream &is)
LOG(debug, "deserialize: format = %d", format);
// Use of bitvector when > 1/32 of docs
if (format == BITVECTOR) {
- BitVector::UP bitVector = BitVector::create(_docIdLimit);
+ auto bitVector = std::make_unique<AllocatedBitVector>(_docIdLimit);
is >> *bitVector;
uint32_t sz(bitVector->size());
assert(sz == _docIdLimit);
diff --git a/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp b/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp
index e811e68f4b5..0658287f29b 100644
--- a/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp
+++ b/searchlib/src/tests/docstore/document_store_visitor/document_store_visitor_test.cpp
@@ -5,7 +5,7 @@
#include <vespa/searchlib/docstore/logdocumentstore.h>
#include <vespa/vespalib/stllike/cache_stats.h>
#include <vespa/searchlib/index/dummyfileheadercontext.h>
-#include <vespa/searchlib/common/bitvector.h>
+#include <vespa/searchlib/common/allocatedbitvector.h>
#include <vespa/document/repo/documenttyperepo.h>
#include <vespa/document/datatype/documenttype.h>
#include <vespa/document/fieldvalue/stringfieldvalue.h>
@@ -95,7 +95,7 @@ public:
uint32_t _visitCount;
uint32_t _visitRmCount;
uint32_t _docIdLimit;
- BitVector::UP _valid;
+ std::unique_ptr<AllocatedBitVector> _valid;
bool _before;
MyVisitorBase(DocumentTypeRepo &repo, uint32_t docIdLimit, bool before);
@@ -106,7 +106,7 @@ MyVisitorBase::MyVisitorBase(DocumentTypeRepo &repo, uint32_t docIdLimit, bool b
_visitCount(0u),
_visitRmCount(0u),
_docIdLimit(docIdLimit),
- _valid(BitVector::create(docIdLimit)),
+ _valid(std::make_unique<AllocatedBitVector>(docIdLimit)),
_before(before)
{
}
@@ -216,7 +216,7 @@ struct Fixture
std::unique_ptr<LogDocumentStore> _store;
uint64_t _syncToken;
uint32_t _docIdLimit;
- BitVector::UP _valid;
+ std::unique_ptr<AllocatedBitVector> _valid;
Fixture();
~Fixture();
@@ -246,7 +246,7 @@ Fixture::Fixture()
_store(),
_syncToken(0u),
_docIdLimit(0u),
- _valid(BitVector::create(0u))
+ _valid(std::make_unique<AllocatedBitVector>(0u))
{
rmdir();
mkdir();
diff --git a/searchlib/src/vespa/searchlib/attribute/flagattribute.cpp b/searchlib/src/vespa/searchlib/attribute/flagattribute.cpp
index 8d137530dd0..d6aa136e15f 100644
--- a/searchlib/src/vespa/searchlib/attribute/flagattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/flagattribute.cpp
@@ -122,7 +122,7 @@ void FlagAttributeT<B>::setNewValues(DocId doc, const std::vector<typename B::WT
BitVector * bv = _bitVectors[offset];
if (bv == nullptr) {
assert(_bitVectorSize >= this->getNumDocs());
- _bitVectorStore[offset] = BitVector::create(_bitVectorSize);
+ _bitVectorStore[offset] = std::make_shared<GrowableBitVector>(_bitVectorSize, _bitVectorSize, _bitVectorHolder);
_bitVectors[offset] = _bitVectorStore[offset].get();
bv = _bitVectors[offset];
ensureGuardBit(*bv);
@@ -139,7 +139,7 @@ FlagAttributeT<B>::setNewBVValue(DocId doc, multivalue::ValueType_t<typename B::
BitVector * bv = _bitVectors[offset];
if (bv == nullptr) {
assert(_bitVectorSize >= this->getNumDocs());
- _bitVectorStore[offset] = BitVector::create(_bitVectorSize);
+ _bitVectorStore[offset] = std::make_shared<GrowableBitVector>(_bitVectorSize, _bitVectorSize, _bitVectorHolder);
_bitVectors[offset] = _bitVectorStore[offset].get();
bv = _bitVectors[offset];
ensureGuardBit(*bv);
@@ -210,11 +210,11 @@ FlagAttributeT<B>::resizeBitVectors(uint32_t neededSize)
{
const GrowStrategy & gs = this->getConfig().getGrowStrategy();
uint32_t newSize = neededSize + (neededSize * gs.getDocsGrowFactor()) + gs.getDocsGrowDelta();
- for (BitVector * bv : _bitVectors) {
+ for (size_t i(0), m(_bitVectors.size()); i < m; i++) {
+ BitVector *bv = _bitVectors[i];
if (bv != nullptr) {
- vespalib::GenerationHeldBase::UP hold(bv->grow(newSize));
+ _bitVectorStore[i]->extend(newSize);
ensureGuardBit(*bv);
- _bitVectorHolder.hold(std::move(hold));
}
}
_bitVectorSize = newSize;
diff --git a/searchlib/src/vespa/searchlib/attribute/flagattribute.h b/searchlib/src/vespa/searchlib/attribute/flagattribute.h
index f88f46bf974..c4f4980e372 100644
--- a/searchlib/src/vespa/searchlib/attribute/flagattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/flagattribute.h
@@ -3,6 +3,7 @@
#include "multinumericattribute.h"
#include "multi_numeric_search_context.h"
+#include <vespa/searchlib/common/growablebitvector.h>
namespace search {
@@ -34,10 +35,10 @@ private:
void removeOldGenerations(vespalib::GenerationHandler::generation_t firstUsed) override;
uint32_t getOffset(int8_t value) const { return value + 128; }
- vespalib::GenerationHolder _bitVectorHolder;
- std::vector<std::shared_ptr<BitVector> > _bitVectorStore;
- std::vector<BitVector *> _bitVectors;
- uint32_t _bitVectorSize;
+ vespalib::GenerationHolder _bitVectorHolder;
+ std::vector<std::shared_ptr<GrowableBitVector> > _bitVectorStore;
+ std::vector<BitVector *> _bitVectors;
+ uint32_t _bitVectorSize;
};
typedef FlagAttributeT<FlagBaseImpl> FlagAttribute;
diff --git a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
index ab56317db6f..f37968c70a0 100644
--- a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
@@ -6,10 +6,6 @@
namespace search {
-using vespalib::GenerationHeldBase;
-using vespalib::GenerationHeldAlloc;
-using vespalib::GenerationHolder;
-
namespace {
size_t computeCapacity(size_t capacity, size_t allocatedBytes) {
@@ -131,30 +127,4 @@ AllocatedBitVector::operator=(const BitVector & rhs)
return *this;
}
-GenerationHeldBase::UP
-AllocatedBitVector::grow(Index newSize, Index newCapacity)
-{
- assert(newCapacity >= newSize);
- GenerationHeldBase::UP ret;
- if (newCapacity != capacity()) {
- AllocatedBitVector tbv(newSize, newCapacity, _alloc.get(), size(), &_alloc);
- if (newSize > size()) {
- tbv.clearBitAndMaintainCount(size()); // Clear old guard bit.
- }
- ret = std::make_unique<GenerationHeldAlloc<Alloc>>(_alloc);
- swap(tbv);
- } else {
- if (newSize > size()) {
- Range clearRange(size(), newSize);
- setSize(newSize);
- clearIntervalNoInvalidation(clearRange);
- } else {
- clearIntervalNoInvalidation(Range(newSize, size()));
- setSize(newSize);
- updateCount();
- }
- }
- return ret;
-}
-
} // namespace search
diff --git a/searchlib/src/vespa/searchlib/common/allocatedbitvector.h b/searchlib/src/vespa/searchlib/common/allocatedbitvector.h
index 2223c7b4701..5106717dad0 100644
--- a/searchlib/src/vespa/searchlib/common/allocatedbitvector.h
+++ b/searchlib/src/vespa/searchlib/common/allocatedbitvector.h
@@ -6,6 +6,7 @@
namespace search {
+class GrowableBitVector;
class BitVectorTest;
/**
@@ -39,7 +40,7 @@ public:
AllocatedBitVector(const BitVector &other);
AllocatedBitVector(const AllocatedBitVector &other);
- virtual ~AllocatedBitVector();
+ ~AllocatedBitVector() override;
AllocatedBitVector &operator=(const AllocatedBitVector &other);
AllocatedBitVector &operator=(const BitVector &other);
@@ -57,9 +58,7 @@ public:
*
* @param newLength the new length of the bit vector (in bits)
*/
- void resize(Index newLength) override;
-
- GenerationHeldBase::UP grow(Index newLength, Index newCapacity) override;
+ void resize(Index newLength);
protected:
Index _capacityBits;
@@ -67,6 +66,7 @@ protected:
private:
friend class BitVectorTest;
+ friend class GrowableBitVector;
void swap(AllocatedBitVector & rhs) {
std::swap(_capacityBits, rhs._capacityBits);
_alloc.swap(rhs._alloc);
diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp
index d5b21a38c3f..36ebc6597fa 100644
--- a/searchlib/src/vespa/searchlib/common/bitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp
@@ -2,7 +2,6 @@
#include "bitvector.h"
#include "allocatedbitvector.h"
-#include "growablebitvector.h"
#include "partialbitvector.h"
#include <vespa/searchlib/util/file_settings.h>
#include <vespa/vespalib/hwaccelrated/iaccelrated.h>
@@ -299,18 +298,6 @@ BitVector::hasTrueBitsInternal() const
}
//////////////////////////////////////////////////////////////////////
-// Set new length. Destruction of content
-//////////////////////////////////////////////////////////////////////
-void
-BitVector::resize(Index)
-{
- LOG_ABORT("should not be reached");
-}
-GenerationHeldBase::UP
-BitVector::grow(Index, Index )
-{
- LOG_ABORT("should not be reached");
-}
size_t
BitVector::getFileBytes(Index bits)
@@ -383,12 +370,6 @@ BitVector::create(const BitVector & rhs)
return std::make_unique<AllocatedBitVector>(rhs);
}
-BitVector::UP
-BitVector::create(Index numberOfElements, Index newCapacity, GenerationHolder &generationHolder)
-{
- return std::make_unique<GrowableBitVector>(numberOfElements, newCapacity, generationHolder);
-}
-
MMappedBitVector::MMappedBitVector(Index numberOfElements, FastOS_FileInterface &file,
int64_t offset, Index doccount) :
BitVector()
@@ -425,7 +406,7 @@ operator<<(nbostream &out, const BitVector &bv)
nbostream &
-operator>>(nbostream &in, BitVector &bv)
+operator>>(nbostream &in, AllocatedBitVector &bv)
{
uint64_t size;
uint64_t cachedHits;
diff --git a/searchlib/src/vespa/searchlib/common/bitvector.h b/searchlib/src/vespa/searchlib/common/bitvector.h
index 53e9ed45d5e..7fea95661d7 100644
--- a/searchlib/src/vespa/searchlib/common/bitvector.h
+++ b/searchlib/src/vespa/searchlib/common/bitvector.h
@@ -18,6 +18,7 @@ class FastOS_FileInterface;
namespace search {
class PartialBitVector;
+class AllocatedBitVector;
class BitVector : protected BitWord
{
@@ -253,11 +254,6 @@ public:
return getFileBytes(size());
}
- virtual void resize(Index newLength);
-
- virtual GenerationHeldBase::UP grow(Index newLength, Index newCapacity);
- GenerationHeldBase::UP grow(Index newLength) { return grow(newLength, newLength); }
-
/**
* This will create the appropriate vector.
*
@@ -271,7 +267,6 @@ public:
static UP create(const BitVector & org, Index start, Index end);
static UP create(Index numberOfElements);
static UP create(const BitVector & rhs);
- static UP create(Index newSize, Index newCapacity, GenerationHolder &generationHolder);
protected:
using Alloc = vespalib::alloc::Alloc;
VESPA_DLL_LOCAL BitVector(void * buf, Index start, Index end);
@@ -384,14 +379,14 @@ protected:
friend vespalib::nbostream &
operator<<(vespalib::nbostream &out, const BitVector &bv);
friend vespalib::nbostream &
- operator>>(vespalib::nbostream &in, BitVector &bv);
+ operator>>(vespalib::nbostream &in, AllocatedBitVector &bv);
};
vespalib::nbostream &
operator<<(vespalib::nbostream &out, const BitVector &bv);
vespalib::nbostream &
-operator>>(vespalib::nbostream &in, BitVector &bv);
+operator>>(vespalib::nbostream &in, AllocatedBitVector &bv);
template <typename T>
void BitVector::andNotWithT(T it) {
diff --git a/searchlib/src/vespa/searchlib/common/growablebitvector.cpp b/searchlib/src/vespa/searchlib/common/growablebitvector.cpp
index 7c29945292e..7a548b3e7ac 100644
--- a/searchlib/src/vespa/searchlib/common/growablebitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/growablebitvector.cpp
@@ -7,8 +7,35 @@
namespace search {
using vespalib::GenerationHeldBase;
+using vespalib::GenerationHeldAlloc;
using vespalib::GenerationHolder;
+GenerationHeldBase::UP
+GrowableBitVector::grow(Index newSize, Index newCapacity)
+{
+ assert(newCapacity >= newSize);
+ GenerationHeldBase::UP ret;
+ if (newCapacity != capacity()) {
+ AllocatedBitVector tbv(newSize, newCapacity, _alloc.get(), size(), &_alloc);
+ if (newSize > size()) {
+ tbv.clearBitAndMaintainCount(size()); // Clear old guard bit.
+ }
+ ret = std::make_unique<GenerationHeldAlloc<Alloc>>(_alloc);
+ swap(tbv);
+ } else {
+ if (newSize > size()) {
+ Range clearRange(size(), newSize);
+ setSize(newSize);
+ clearIntervalNoInvalidation(clearRange);
+ } else {
+ clearIntervalNoInvalidation(Range(newSize, size()));
+ setSize(newSize);
+ updateCount();
+ }
+ }
+ return ret;
+}
+
GrowableBitVector::GrowableBitVector(Index newSize, Index newCapacity,
GenerationHolder &generationHolder,
const Alloc* init_alloc)
diff --git a/searchlib/src/vespa/searchlib/common/growablebitvector.h b/searchlib/src/vespa/searchlib/common/growablebitvector.h
index 71261e130b6..8773f1573d6 100644
--- a/searchlib/src/vespa/searchlib/common/growablebitvector.h
+++ b/searchlib/src/vespa/searchlib/common/growablebitvector.h
@@ -16,6 +16,8 @@ public:
bool shrink(Index newCapacity);
bool extend(Index newCapacity);
private:
+ GenerationHeldBase::UP grow(Index newLength, Index newCapacity);
+
VESPA_DLL_LOCAL bool hold(GenerationHeldBase::UP v);
GenerationHolder &_generationHolder;
};