diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2016-10-05 06:48:56 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2016-10-05 06:50:47 +0000 |
commit | 6ec7b21e74fdb06058836fb8fb61420428f9955c (patch) | |
tree | 123c134f66fa88cb8d2f1815117d048013d8cb6c /searchlib | |
parent | 2814c54e91009b5f023fea8fc8d073e8b8062eb7 (diff) |
Signal in constructor that we only have 32 bits available for docid.
Use only 32 bits for offset.
Reduce vertical bloat.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/tests/attribute/multivaluemapping/multivaluemapping_test.cpp | 12 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/attribute/multivaluemapping.h | 142 |
2 files changed, 37 insertions, 117 deletions
diff --git a/searchlib/src/tests/attribute/multivaluemapping/multivaluemapping_test.cpp b/searchlib/src/tests/attribute/multivaluemapping/multivaluemapping_test.cpp index 7be95e0d403..48768da32c5 100644 --- a/searchlib/src/tests/attribute/multivaluemapping/multivaluemapping_test.cpp +++ b/searchlib/src/tests/attribute/multivaluemapping/multivaluemapping_test.cpp @@ -115,7 +115,7 @@ MultiValueMappingTest::testIndex64() EXPECT_EQUAL(idx.alternative(), 0u); EXPECT_EQUAL(idx.vectorIdx(), 6u); EXPECT_EQUAL(idx.offset(), 1000u); - EXPECT_EQUAL(idx.idx(), 0x600000003e8ul); + EXPECT_EQUAL(idx.idx(), 0x6000003e8ul); } { Index64 idx(15, 1, 134217727); @@ -123,20 +123,20 @@ MultiValueMappingTest::testIndex64() EXPECT_EQUAL(idx.alternative(), 1u); EXPECT_EQUAL(idx.vectorIdx(), 31u); EXPECT_EQUAL(idx.offset(), 134217727u); - EXPECT_EQUAL(idx.idx(), 0x1f0007fffffful); + EXPECT_EQUAL(idx.idx(), 0x1f07fffffful); } { - Index64 idx(3087, 1, 911134217727ul); + Index64 idx(3087, 1, 0xfffffffful); EXPECT_EQUAL(idx.values(), 3087u); EXPECT_EQUAL(idx.alternative(), 1u); EXPECT_EQUAL(idx.vectorIdx(), (3087u << 1) + 1); - EXPECT_EQUAL(idx.offset(), 911134217727ul); - EXPECT_EQUAL(idx.idx(), 0x181fd423d4d5fful); + EXPECT_EQUAL(idx.offset(), 0xfffffffful); + EXPECT_EQUAL(idx.idx(), 0x181ffffffffful); } { EXPECT_EQUAL(Index64::maxValues(), 4095u); EXPECT_EQUAL(Index64::alternativeSize(), 2u); - EXPECT_EQUAL(Index64::offsetSize(), 0x1ul << 40); + EXPECT_EQUAL(Index64::offsetSize(), 0x1ul << 32); } } diff --git a/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h b/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h index ff98aa4bfdf..a191e40f59f 100644 --- a/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h +++ b/searchlib/src/vespa/searchlib/attribute/multivaluemapping.h @@ -30,62 +30,29 @@ private: T _idx; public: Index() : _idx(0) {} - Index(uint32_t values_, uint32_t alternative_, uint64_t offset_) + Index(uint32_t values_, uint32_t alternative_, uint32_t offset_) : _idx(0) { _idx += static_cast<T>(values_) << (NUM_ALT_BITS+NUM_OFFSET_BITS); - _idx += static_cast<T>((alternative_) & - ((1<<NUM_ALT_BITS) - 1)) << NUM_OFFSET_BITS; + _idx += static_cast<T>((alternative_) & ((1<<NUM_ALT_BITS) - 1)) << NUM_OFFSET_BITS; _idx += offset_; } - uint32_t - values() const - { - return _idx >> (NUM_ALT_BITS+NUM_OFFSET_BITS); - } - - uint32_t - alternative() const - { - return (_idx >> NUM_OFFSET_BITS) & ((1<<NUM_ALT_BITS) - 1); - } + uint32_t values() const { return _idx >> (NUM_ALT_BITS+NUM_OFFSET_BITS); } + uint32_t alternative() const { return (_idx >> NUM_OFFSET_BITS) & ((1<<NUM_ALT_BITS) - 1); } // values and alternative combined - uint32_t - vectorIdx() const - { - return _idx >> NUM_OFFSET_BITS; - } - - uint64_t offset() const - { - return (_idx & ((1ul << NUM_OFFSET_BITS) - 1)); - } - - T idx() const { return _idx; } - - static uint32_t - maxValues() - { - return (1 << NUM_VALUE_BITS) - 1; - } - - static uint32_t - alternativeSize() - { - return 1 << NUM_ALT_BITS; - } + uint32_t vectorIdx() const { return _idx >> NUM_OFFSET_BITS; } + uint64_t offset() const { return (_idx & ((1ul << NUM_OFFSET_BITS) - 1)); } + T idx() const { return _idx; } - static uint64_t - offsetSize() - { - return 1ul << (NUM_OFFSET_BITS); - } + static uint32_t maxValues() { return (1 << NUM_VALUE_BITS) - 1; } + static uint32_t alternativeSize() { return 1 << NUM_ALT_BITS; } + static uint64_t offsetSize() { return 1ul << (NUM_OFFSET_BITS); } }; typedef Index<uint32_t, 27,4,1> Index32; -typedef Index<uint64_t, 40,12,1> Index64; +typedef Index<uint64_t, 32,12,1> Index64; template <typename T, typename I> struct MVMTemplateArg { @@ -180,22 +147,15 @@ public: Histogram getHistogram(AttributeVector::ReaderBase & reader) const; size_t getTotalValueCnt() const { return _totalValueCnt; } static void failNewSize(uint64_t minNewSize, uint64_t maxSize); + void clearPendingCompact(); - void - clearPendingCompact(); - - static size_t - computeNewSize(size_t used, size_t dead, size_t needed, size_t maxSize); + static size_t computeNewSize(size_t used, size_t dead, size_t needed, size_t maxSize); - void - transferHoldLists(generation_t generation) - { + void transferHoldLists(generation_t generation) { _genHolder.transferHoldLists(generation); } - void - trimHoldLists(generation_t firstUsed) - { + void trimHoldLists(generation_t firstUsed) { _genHolder.trimHoldLists(firstUsed); } }; @@ -226,71 +186,36 @@ private: public: using IndexCopyVector = vespalib::Array<Index, vespalib::DefaultAlloc>; - void - doneHoldVector(Index idx); + void doneHoldVector(Index idx); - virtual Histogram getEmptyHistogram() const override { + Histogram getEmptyHistogram() const override { return MultiValueMappingBaseBase::getEmptyHistogram(Index::maxValues()); } - virtual MemoryUsage getMemoryUsage() const override; - + MemoryUsage getMemoryUsage() const override; AddressSpace getAddressSpaceUsage() const; + size_t getNumKeys() const { return _indices.size(); } + size_t getCapacityKeys() const { return _indices.capacity(); } - size_t getNumKeys() const - { - return _indices.size(); - } - - size_t getCapacityKeys() const - { - return _indices.capacity(); - } - - IndexCopyVector - getIndicesCopy() const - { + IndexCopyVector getIndicesCopy() const { uint32_t size = _committedDocIdLimit; assert(size <= _indices.size()); return IndexCopyVector(&_indices[0], &_indices[0] + size); } - bool - hasKey(uint32_t key) const - { - return key < _indices.size(); - } - - bool - hasReaderKey(uint32_t key) const - { + bool hasReaderKey(uint32_t key) const { return key < _committedDocIdLimit && key < _indices.size(); } - bool - isFull() const - { - return _indices.isFull(); - } - - static size_t - maxValues() - { - return Index::maxValues(); - } - - void - addKey(uint32_t & key); - - void - shrinkKeys(uint32_t newSize); - - void - clearDocs(uint32_t lidLow, uint32_t lidLimit, AttributeVector &v); - + bool hasKey(uint32_t key) const { return key < _indices.size(); } + bool isFull() const { return _indices.isFull(); } + void addKey(uint32_t & key); + void shrinkKeys(uint32_t newSize); + void clearDocs(uint32_t lidLow, uint32_t lidLimit, AttributeVector &v); void holdElem(Index idx, size_t size); - virtual void doneHoldElem(Index idx) = 0; + + static size_t maxValues() { return Index::maxValues(); } }; extern template class MultiValueMappingBase<multivalue::Index32>; @@ -302,18 +227,14 @@ class MultiValueMappingFallbackVectorHold { V _hold; public: - MultiValueMappingFallbackVectorHold(size_t size, - V &rhs) + MultiValueMappingFallbackVectorHold(size_t size, V &rhs) : vespalib::GenerationHeldBase(size), _hold() { _hold.swap(rhs); } - virtual - ~MultiValueMappingFallbackVectorHold() - { - } + virtual ~MultiValueMappingFallbackVectorHold() { } }; @@ -1367,4 +1288,3 @@ extern template class MultiValueMappingT< multivalue::Index64>; } // namespace search - |