diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-11-06 15:12:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-06 15:12:44 +0100 |
commit | 0689f93f9750f9d8c0fdbb383388b03c918ce11a (patch) | |
tree | 1e841a2606945279ac229de2850d8e1952060021 /searchlib | |
parent | e173db372c589cf933e47a1e1829befb4eba1568 (diff) | |
parent | ca142fd33fd5c726da8ba5082b3312418ea64b3f (diff) |
Merge pull request #7575 from vespa-engine/balder/use-larger-leafs-for-postinglists
Balder/use larger leafs for postinglists
Diffstat (limited to 'searchlib')
44 files changed, 331 insertions, 816 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/attributeiterators.cpp b/searchlib/src/vespa/searchlib/attribute/attributeiterators.cpp index 2ca92f6a264..3f86a7f57db 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributeiterators.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributeiterators.cpp @@ -3,9 +3,6 @@ #include "attributeiterators.hpp" #include "postinglistattribute.h" -#include <vespa/log/log.h> -LOG_SETUP(".searchlib.attribute.attribute_iterators"); - namespace search { using queryeval::MinMaxPostingInfo; @@ -77,12 +74,7 @@ FilterAttributeIterator::doUnpack(uint32_t docId) template <> void -AttributePostingListIteratorT<btree:: -BTreeConstIterator<uint32_t, - btree::BTreeNoLeafData, - btree::NoAggregated, - std::less<uint32_t>, - btree::BTreeDefaultTraits> >:: +AttributePostingListIteratorT<InnerAttributePostingListIterator>:: doUnpack(uint32_t docId) { _matchData->resetOnlyDocId(docId); @@ -92,12 +84,7 @@ doUnpack(uint32_t docId) template <> void -AttributePostingListIteratorT<btree:: -BTreeConstIterator<uint32_t, - int32_t, - btree::MinMaxAggregated, - std::less<uint32_t>, - btree::BTreeDefaultTraits> >:: +AttributePostingListIteratorT<WeightedInnerAttributePostingListIterator>:: doUnpack(uint32_t docId) { _matchData->resetOnlyDocId(docId); @@ -107,12 +94,7 @@ doUnpack(uint32_t docId) template <> void -FilterAttributePostingListIteratorT<btree:: -BTreeConstIterator<uint32_t, - btree::BTreeNoLeafData, - btree::NoAggregated, - std::less<uint32_t>, - btree::BTreeDefaultTraits> >:: +FilterAttributePostingListIteratorT<InnerAttributePostingListIterator>:: doUnpack(uint32_t docId) { _matchData->resetOnlyDocId(docId); @@ -121,12 +103,7 @@ doUnpack(uint32_t docId) template <> void -FilterAttributePostingListIteratorT<btree:: -BTreeConstIterator<uint32_t, - int32_t, - btree::MinMaxAggregated, - std::less<uint32_t>, - btree::BTreeDefaultTraits> >:: +FilterAttributePostingListIteratorT<WeightedInnerAttributePostingListIterator>:: doUnpack(uint32_t docId) { _matchData->resetOnlyDocId(docId); diff --git a/searchlib/src/vespa/searchlib/attribute/attributeiterators.h b/searchlib/src/vespa/searchlib/attribute/attributeiterators.h index bb4acdbd732..0fbcab03ec0 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributeiterators.h +++ b/searchlib/src/vespa/searchlib/attribute/attributeiterators.h @@ -3,9 +3,8 @@ #pragma once #include "dociditerator.h" +#include "postinglisttraits.h" #include <vespa/searchlib/queryeval/searchiterator.h> -#include <vespa/searchlib/btree/btreenode.h> -#include <vespa/searchlib/btree/btreeiterator.h> namespace search { @@ -183,19 +182,9 @@ public: }; -typedef btree::BTreeConstIterator<uint32_t, - btree::BTreeNoLeafData, - btree::NoAggregated, - std::less<uint32_t>, - btree::BTreeDefaultTraits> -InnerAttributePostingListIterator; +using InnerAttributePostingListIterator = attribute::PostingListTraits<btree::BTreeNoLeafData>::const_iterator; -typedef btree::BTreeConstIterator<uint32_t, - int32_t, - btree::MinMaxAggregated, - std::less<uint32_t>, - btree::BTreeDefaultTraits> -WeightedInnerAttributePostingListIterator; +using WeightedInnerAttributePostingListIterator = attribute::PostingListTraits<int32_t>::const_iterator; template <typename PL> class AttributePostingListIteratorT : public AttributePostingListIterator @@ -211,7 +200,7 @@ private: int32_t getWeight() { return _iterator.getData(); } const queryeval::PostingInfo * getPostingInfo() const override { - return _postingInfoValid ? &_postingInfo : NULL; + return _postingInfoValid ? &_postingInfo : nullptr; } void initRange(uint32_t begin, uint32_t end) override; @@ -246,7 +235,7 @@ private: void setupPostingInfo() { } const queryeval::PostingInfo * getPostingInfo() const override { - return _postingInfoValid ? &_postingInfo : NULL; + return _postingInfoValid ? &_postingInfo : nullptr; } void initRange(uint32_t begin, uint32_t end) override; @@ -259,12 +248,7 @@ public: template <> inline int32_t -AttributePostingListIteratorT< - btree::BTreeConstIterator<uint32_t, - btree::BTreeNoLeafData, - btree::NoAggregated, - std::less<uint32_t>, - btree::BTreeDefaultTraits> >:: +AttributePostingListIteratorT<InnerAttributePostingListIterator>:: getWeight() { return 1; // default weight 1 for single value attributes @@ -272,15 +256,13 @@ getWeight() template <> void -AttributePostingListIteratorT<btree::BTreeConstIterator<uint32_t, btree::BTreeNoLeafData, btree::NoAggregated, - std::less<uint32_t>, btree::BTreeDefaultTraits> >:: +AttributePostingListIteratorT<InnerAttributePostingListIterator >:: doUnpack(uint32_t docId); template <> void -AttributePostingListIteratorT<btree::BTreeConstIterator<uint32_t, int32_t, btree::MinMaxAggregated, - std::less<uint32_t>, btree::BTreeDefaultTraits> >:: +AttributePostingListIteratorT<WeightedInnerAttributePostingListIterator>:: doUnpack(uint32_t docId); diff --git a/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp b/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp index e52a393fc11..d1165ed20e1 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp +++ b/searchlib/src/vespa/searchlib/attribute/attributeiterators.hpp @@ -236,7 +236,7 @@ FlagAttributeIteratorStrict<SC>::doSeek(uint32_t docId) const Attribute &attr = static_cast<const Attribute &>(sc.attribute()); for (int i = sc._low; (i <= sc._high); ++i) { const BitVector * bv = attr.getBitVector(i); - if ((bv != NULL) && !isAtEnd(docId) && bv->testBit(docId)) { + if ((bv != nullptr) && !isAtEnd(docId) && bv->testBit(docId)) { setDocId(docId); return; } @@ -245,7 +245,7 @@ FlagAttributeIteratorStrict<SC>::doSeek(uint32_t docId) uint32_t minNextBit(search::endDocId); for (int i = sc._low; (i <= sc._high); ++i) { const BitVector * bv = attr.getBitVector(i); - if (bv != NULL && !isAtEnd(docId)) { + if (bv != nullptr && !isAtEnd(docId)) { uint32_t nextBit = bv->getNextTrueBit(docId); minNextBit = std::min(nextBit, minNextBit); } @@ -265,7 +265,7 @@ FlagAttributeIteratorT<SC>::doSeek(uint32_t docId) const Attribute &attr = static_cast<const Attribute &>(sc.attribute()); for (int i = sc._low; (i <= sc._high); ++i) { const BitVector * bv = attr.getBitVector(i); - if ((bv != NULL) && !isAtEnd(docId) && bv->testBit(docId)) { + if ((bv != nullptr) && !isAtEnd(docId) && bv->testBit(docId)) { setDocId(docId); return; } @@ -280,7 +280,7 @@ FlagAttributeIteratorT<SC>::or_hits_into(BitVector &result, uint32_t begin_id) { const Attribute &attr = static_cast<const Attribute &>(sc.attribute()); for (int i = sc._low; (i <= sc._high); ++i) { const BitVector * bv = attr.getBitVector(i); - if (bv != NULL) { + if (bv != nullptr) { result.orWith(*bv); } } @@ -293,7 +293,7 @@ FlagAttributeIteratorT<SC>::and_hits_into(BitVector &result, uint32_t begin_id) const Attribute &attr = static_cast<const Attribute &>(sc.attribute()); if (sc._low == sc._high) { const BitVector * bv = attr.getBitVector(sc._low); - if (bv != NULL) { + if (bv != nullptr) { result.andWith(*bv); } else { // I would expect us never to end up in this case as we are probably @@ -314,14 +314,14 @@ FlagAttributeIteratorT<SC>::get_hits(uint32_t begin_id) { BitVector::UP result; for (;!result && i < sc._high; ++i) { const BitVector * bv = attr.getBitVector(i); - if (bv != NULL) { + if (bv != nullptr) { result = BitVector::create(*bv, begin_id, getEndId()); } } for (; i <= sc._high; ++i) { const BitVector * bv = attr.getBitVector(i); - if (bv != NULL) { + if (bv != nullptr) { result->orWith(*bv); } } diff --git a/searchlib/src/vespa/searchlib/attribute/dociditerator.h b/searchlib/src/vespa/searchlib/attribute/dociditerator.h index c69d6035f49..1eb1829f3fd 100644 --- a/searchlib/src/vespa/searchlib/attribute/dociditerator.h +++ b/searchlib/src/vespa/searchlib/attribute/dociditerator.h @@ -2,7 +2,9 @@ #pragma once -#include "postinglisttraits.h" +#include "postingdata.h" +#include <vespa/searchlib/btree/minmaxaggregated.h> +#include <algorithm> namespace search { diff --git a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp index 7cad3f7d1d3..7f74d61c1f7 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp +++ b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.cpp @@ -3,12 +3,9 @@ #include "enumhintsearchcontext.h" #include <vespa/searchlib/queryeval/emptysearch.h> -namespace search { +namespace search::attribute { using queryeval::SearchIterator; - -namespace attribute { - using btree::BTreeNode; using fef::TermFieldMatchData; @@ -25,9 +22,7 @@ EnumHintSearchContext(const EnumStoreDictBase &dictionary, } -EnumHintSearchContext::~EnumHintSearchContext() -{ -} +EnumHintSearchContext::~EnumHintSearchContext() = default; void @@ -51,14 +46,10 @@ EnumHintSearchContext::fetchPostings(bool strict) } SearchIterator::UP -EnumHintSearchContext::createPostingIterator(TermFieldMatchData *matchData, - bool strict) +EnumHintSearchContext::createPostingIterator(TermFieldMatchData *, bool ) { - (void) matchData; - (void) strict; - return (_uniqueValues == 0u) - ? SearchIterator::UP(new queryeval::EmptySearch()) + ? std::make_unique<queryeval::EmptySearch>() : SearchIterator::UP(); } @@ -71,6 +62,4 @@ EnumHintSearchContext::approximateHits() const : std::max(uint64_t(_docIdLimit), _numValues); } -} // namespace attribute - -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h index be315b05a69..7d6d31fce50 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h +++ b/searchlib/src/vespa/searchlib/attribute/enumhintsearchcontext.h @@ -3,15 +3,10 @@ #pragma once #include "enumstore.h" -#include "postinglisttraits.h" #include "ipostinglistsearchcontext.h" #include <vespa/searchlib/queryeval/searchiterator.h> -namespace search -{ - -namespace attribute -{ +namespace search::attribute { /** * Search context helper for enumerated attributes, used to eliminate @@ -42,8 +37,4 @@ protected: unsigned int approximateHits() const override; }; - -} // namespace attribute - -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp b/searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp index 142883e54d6..ba6ba0ef6ee 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp +++ b/searchlib/src/vespa/searchlib/attribute/enumstorebase.cpp @@ -3,11 +3,12 @@ #include "enumstorebase.h" #include "enumstore.h" #include <vespa/searchlib/datastore/datastore.hpp> -#include <vespa/vespalib/util/exceptions.h> #include <vespa/searchlib/btree/btreeiterator.hpp> #include <vespa/searchlib/btree/btreenode.hpp> #include <vespa/searchlib/util/bufferwriter.h> #include <vespa/searchlib/common/rcuvector.hpp> +#include <vespa/vespalib/util/exceptions.h> +#include <vespa/vespalib/stllike/asciistream.h> #include <vespa/log/log.h> LOG_SETUP(".searchlib.attribute.enumstorebase"); @@ -34,7 +35,7 @@ EnumStoreBase::EnumBufferType::calcClustersToAlloc(uint32_t bufferId, size_t siz size_t reservedElements = getReservedElements(bufferId); sizeNeeded = std::max(sizeNeeded, _minSizeNeeded); size_t usedElems = _activeUsedElems; - if (_lastUsedElems != NULL) { + if (_lastUsedElems != nullptr) { usedElems += *_lastUsedElems; } assert((usedElems % _clusterSize) == 0); @@ -62,7 +63,7 @@ EnumStoreBase::EnumBufferType::calcClustersToAlloc(uint32_t bufferId, size_t siz EnumStoreBase::EnumStoreBase(uint64_t initBufferSize, bool hasPostings) - : _enumDict(NULL), + : _enumDict(nullptr), _store(), _type(), _nextEnum(0), @@ -314,9 +315,7 @@ EnumStoreDictBase::EnumStoreDictBase(EnumStoreBase &enumStore) } -EnumStoreDictBase::~EnumStoreDictBase() -{ -} +EnumStoreDictBase::~EnumStoreDictBase() = default; template <typename Dictionary> @@ -327,9 +326,7 @@ EnumStoreDict<Dictionary>::EnumStoreDict(EnumStoreBase &enumStore) } template <typename Dictionary> -EnumStoreDict<Dictionary>::~EnumStoreDict() -{ -} +EnumStoreDict<Dictionary>::~EnumStoreDict() = default; template <typename Dictionary> @@ -418,7 +415,7 @@ EnumStoreDict<Dictionary>::removeUnusedEnums(const IndexSet &unused, iter != mt; ++iter) { it.lower_bound(_dict.getRoot(), *iter, cmp); assert(it.valid() && !cmp(*iter, it.getKey())); - if (Iterator::hasData() && fcmp != NULL) { + if (Iterator::hasData() && fcmp != nullptr) { typename Dictionary::DataType pidx(it.getData()); _dict.remove(it); if (!it.valid() || (*fcmp)(*iter, it.getKey())) diff --git a/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h b/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h index 7798d3efb3a..dc0a92c4a4f 100644 --- a/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h +++ b/searchlib/src/vespa/searchlib/attribute/i_document_weight_attribute.h @@ -2,14 +2,13 @@ #pragma once -#include <vespa/searchlib/datastore/entryref.h> -#include <vespa/searchlib/btree/btreeiterator.h> +#include "postinglisttraits.h" namespace search { namespace query { class Node; } -typedef btree::BTreeConstIterator<uint32_t, int32_t, btree::MinMaxAggregated, std::less<uint32_t>, btree::BTreeDefaultTraits> DocumentWeightIterator; +using DocumentWeightIterator = attribute::PostingListTraits<int32_t>::const_iterator; struct IDocumentWeightAttribute { @@ -28,5 +27,5 @@ struct IDocumentWeightAttribute virtual ~IDocumentWeightAttribute() {} }; -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/attribute/postingchange.h b/searchlib/src/vespa/searchlib/attribute/postingchange.h index 35260f9bb53..00904954a2b 100644 --- a/searchlib/src/vespa/searchlib/attribute/postingchange.h +++ b/searchlib/src/vespa/searchlib/attribute/postingchange.h @@ -2,12 +2,11 @@ #pragma once -#include <vespa/vespalib/util/array.h> -#include "postinglisttraits.h" +#include "postingdata.h" #include "enumstorebase.h" +#include <vespa/vespalib/util/array.h> -namespace search -{ +namespace search { class GrowableBitVector; @@ -81,7 +80,6 @@ PostingChange<AttributeWeightPosting>::add(uint32_t docId, int32_t weight) _additions.push_back(AttributeWeightPosting(docId, weight)); } - } // namespace search diff --git a/searchlib/src/vespa/searchlib/attribute/postingdata.h b/searchlib/src/vespa/searchlib/attribute/postingdata.h new file mode 100644 index 00000000000..001e1015d19 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/postingdata.h @@ -0,0 +1,13 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <vespa/searchlib/btree/btree_key_data.h> + +namespace search { + +using AttributePosting = btree::BTreeKeyData<uint32_t, btree::BTreeNoLeafData>; +using AttributeWeightPosting = btree::BTreeKeyData<uint32_t, int32_t>; + +} + diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp index e17389ea532..4c2c0043de8 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp @@ -6,13 +6,7 @@ #include "diversity.hpp" #include <vespa/searchlib/btree/btreeiterator.hpp> -#include <vespa/log/log.h> -LOG_SETUP(".searchlib.attribute.posting_list_search_context"); - - -namespace search { - -namespace attribute { +namespace search::attribute { using btree::BTreeNode; @@ -89,7 +83,4 @@ template class PostingListSearchContextT<int32_t>; template class PostingListFoldedSearchContextT<btree::BTreeNoLeafData>; template class PostingListFoldedSearchContextT<int32_t>; - -} // namespace attribute - -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/attribute/postinglisttraits.cpp b/searchlib/src/vespa/searchlib/attribute/postinglisttraits.cpp index 35c2c7ffad9..28a4a51c84c 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglisttraits.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglisttraits.cpp @@ -1,8 +1,34 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "postinglisttraits.h" +#include <vespa/searchlib/btree/btreestore.hpp> +#include <vespa/searchlib/btree/btreeroot.hpp> +#include <vespa/searchlib/btree/btreenodeallocator.hpp> +#include <vespa/searchlib/btree/btreebuilder.hpp> +#include <vespa/searchlib/btree/btreeiterator.hpp> namespace search { +using btree::BTreeNoLeafData; +using NoD = attribute::PostingListTraits<BTreeNoLeafData>; +using WD = attribute::PostingListTraits<int32_t>; + +template class btree::BTreeStore<uint32_t, BTreeNoLeafData, NoD::AggregatedType, std::less<uint32_t>, NoD::BTreeTraits, NoD::AggrCalcType>; +template class btree::BTreeRoot<uint32_t, BTreeNoLeafData, NoD::AggregatedType, std::less<uint32_t>, NoD::BTreeTraits, NoD::AggrCalcType>; +template class btree::BTreeRootT<uint32_t, BTreeNoLeafData, NoD::AggregatedType, std::less<uint32_t>, NoD::BTreeTraits>; +template class btree::BTreeNodeAllocator<uint32_t, BTreeNoLeafData, NoD::AggregatedType, NoD::BTreeTraits::INTERNAL_SLOTS, NoD::BTreeTraits::LEAF_SLOTS>; +template class btree::BTreeBuilder<uint32_t, BTreeNoLeafData, NoD::AggregatedType, NoD::BTreeTraits::INTERNAL_SLOTS, NoD::BTreeTraits::LEAF_SLOTS, NoD::AggrCalcType>; +template class btree::BTreeIteratorBase<uint32_t, BTreeNoLeafData, NoD::AggregatedType, NoD::BTreeTraits::INTERNAL_SLOTS, NoD::BTreeTraits::LEAF_SLOTS, NoD::BTreeTraits::PATH_SIZE>; +template class btree::BTreeConstIterator<uint32_t, BTreeNoLeafData, NoD::AggregatedType, std::less<uint32_t>, NoD::BTreeTraits>; + +template class btree::BTreeStore<uint32_t, int32_t, WD::AggregatedType, std::less<uint32_t>, WD::BTreeTraits, WD::AggrCalcType>; +template class btree::BTreeRoot<uint32_t, int32_t, WD::AggregatedType, std::less<uint32_t>, WD::BTreeTraits, WD::AggrCalcType>; +template class btree::BTreeRootT<uint32_t, int32_t, WD::AggregatedType, std::less<uint32_t>, WD::BTreeTraits>; +template class btree::BTreeNodeAllocator<uint32_t, int32_t, WD::AggregatedType, WD::BTreeTraits::INTERNAL_SLOTS, WD::BTreeTraits::LEAF_SLOTS>; +template class btree::BTreeBuilder<uint32_t, int32_t, WD::AggregatedType, WD::BTreeTraits::INTERNAL_SLOTS, WD::BTreeTraits::LEAF_SLOTS, WD::AggrCalcType>; +template class btree::BTreeIteratorBase<uint32_t, int32_t, WD::AggregatedType, WD::BTreeTraits::INTERNAL_SLOTS, WD::BTreeTraits::LEAF_SLOTS, WD::BTreeTraits::PATH_SIZE>; +template class btree::BTreeConstIterator<uint32_t, int32_t, WD::AggregatedType, std::less<uint32_t>, WD::BTreeTraits>; +template class btree::BTreeAggregator<uint32_t, int32_t, WD::AggregatedType, WD::BTreeTraits::INTERNAL_SLOTS, WD::BTreeTraits::LEAF_SLOTS, WD::AggrCalcType >; + } // namespace search diff --git a/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h b/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h index 9a665aa4fed..3a03a03641f 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h +++ b/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h @@ -4,9 +4,7 @@ #include <vespa/searchlib/btree/btreestore.h> -namespace search { - -namespace attribute { +namespace search::attribute { template <typename DataT> class PostingListTraits; template <typename DataT> class PostingStore; @@ -14,41 +12,29 @@ template <typename DataT> class PostingStore; template <> class PostingListTraits<btree::BTreeNoLeafData> { +private: + using BTreeTraits = btree::BTreeTraits<64, 16, 8, true>; public: - typedef btree::NoAggregated AggregatedType; - typedef btree::NoAggrCalc AggrCalcType; - typedef btree::BTreeStore<uint32_t, btree::BTreeNoLeafData, - AggregatedType, - std::less<uint32_t>, - btree::BTreeDefaultTraits, - AggrCalcType> PostingStoreBase; - typedef PostingStore<btree::BTreeNoLeafData> PostingList; - typedef PostingStoreBase::KeyDataType Posting; + using AggregatedType = btree::NoAggregated; + using AggrCalcType = btree::NoAggrCalc; + using const_iterator = btree::BTreeConstIterator<uint32_t, btree::BTreeNoLeafData, AggregatedType, std::less<uint32_t>, BTreeTraits >; + using PostingStoreBase = btree::BTreeStore<uint32_t, btree::BTreeNoLeafData, AggregatedType, std::less<uint32_t>, BTreeTraits, AggrCalcType> ; + using PostingList = PostingStore<btree::BTreeNoLeafData>; + using Posting = PostingStoreBase::KeyDataType; }; - template <> class PostingListTraits<int32_t> { +private: + using BTreeTraits = btree::BTreeTraits<32, 16, 9, true>; public: - typedef btree::MinMaxAggregated AggregatedType; - typedef btree::MinMaxAggrCalc AggrCalcType; - typedef btree::BTreeStore<uint32_t, int32_t, - AggregatedType, - std::less<uint32_t>, - btree::BTreeDefaultTraits, - AggrCalcType> PostingStoreBase; - typedef PostingStore<int32_t> PostingList; - typedef PostingStoreBase::KeyDataType Posting; + using AggregatedType = btree::MinMaxAggregated; + using AggrCalcType = btree::MinMaxAggrCalc; + using const_iterator = btree::BTreeConstIterator<uint32_t, int32_t, AggregatedType, std::less<uint32_t>, BTreeTraits >; + using PostingStoreBase = btree::BTreeStore<uint32_t, int32_t, AggregatedType, std::less<uint32_t>, BTreeTraits, AggrCalcType>; + using PostingList = PostingStore<int32_t>; + using Posting = PostingStoreBase::KeyDataType; }; - -} // namespace attribute - -typedef btree::BTreeKeyData<uint32_t, btree::BTreeNoLeafData> AttributePosting; - -typedef btree::BTreeKeyData<uint32_t, int32_t> AttributeWeightPosting; - - -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/attribute/postingstore.cpp b/searchlib/src/vespa/searchlib/attribute/postingstore.cpp index a0fa7e35054..e5fb1fa480a 100644 --- a/searchlib/src/vespa/searchlib/attribute/postingstore.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postingstore.cpp @@ -7,8 +7,6 @@ #include <vespa/searchcommon/attribute/config.h> #include <vespa/searchcommon/attribute/status.h> -#include <vespa/log/log.h> -LOG_SETUP(".searchlib.attribute.posting_store"); namespace search::attribute { @@ -39,9 +37,7 @@ PostingStoreBase2::PostingStoreBase2(EnumPostingTree &dict, Status &status, } -PostingStoreBase2::~PostingStoreBase2() -{ -} +PostingStoreBase2::~PostingStoreBase2() = default; bool @@ -632,9 +628,7 @@ PostingStore<DataT>::getMemoryUsage() const return usage; } - template class PostingStore<BTreeNoLeafData>; - template class PostingStore<int32_t>; } diff --git a/searchlib/src/vespa/searchlib/btree/btreeaggregator.cpp b/searchlib/src/vespa/searchlib/btree/btreeaggregator.cpp index 1efa6a7f099..2eb627192dc 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeaggregator.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreeaggregator.cpp @@ -1,8 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "btreetraits.h" #include "btreeaggregator.hpp" -#include "noaggrcalc.h" #include "minmaxaggrcalc.h" namespace search::btree { diff --git a/searchlib/src/vespa/searchlib/btree/btreeaggregator.h b/searchlib/src/vespa/searchlib/btree/btreeaggregator.h index 95c03b11ef8..38c6f579f53 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeaggregator.h +++ b/searchlib/src/vespa/searchlib/btree/btreeaggregator.h @@ -7,11 +7,7 @@ #include "btreetraits.h" #include "noaggrcalc.h" -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename KeyT, typename DataT, @@ -22,47 +18,25 @@ template <typename KeyT, class BTreeAggregator { public: - typedef BTreeNodeAllocator<KeyT, DataT, AggrT, - INTERNAL_SLOTS, - LEAF_SLOTS> NodeAllocatorType; - typedef BTreeInternalNode<KeyT, AggrT, INTERNAL_SLOTS> - InternalNodeType; - typedef BTreeLeafNode<KeyT, DataT, AggrT, LEAF_SLOTS> - LeafNodeType; - typedef AggrT AggregatedType; + using NodeAllocatorType = BTreeNodeAllocator<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>; + using InternalNodeType = BTreeInternalNode<KeyT, AggrT, INTERNAL_SLOTS>; + using LeafNodeType = BTreeLeafNode<KeyT, DataT, AggrT, LEAF_SLOTS>; + using AggregatedType = AggrT; static AggrT aggregate(const LeafNodeType &node, AggrCalcT aggrCalc); static AggrT aggregate(const InternalNodeType &node, const NodeAllocatorType &allocator, AggrCalcT aggrCalc); - static void - recalc(LeafNodeType &node, const AggrCalcT &aggrCalc); + static void recalc(LeafNodeType &node, const AggrCalcT &aggrCalc); - static void - recalc(LeafNodeType &node, - const NodeAllocatorType &allocator, - const AggrCalcT &aggrCalc) - { - (void) allocator; + static void recalc(LeafNodeType &node, const NodeAllocatorType &, const AggrCalcT &aggrCalc) { recalc(node, aggrCalc); } - static void - recalc(InternalNodeType &node, - const NodeAllocatorType &allocator, - const AggrCalcT &aggrCalc); - - static AggregatedType - recalc(LeafNodeType &node, - LeafNodeType &splitNode, - const AggrCalcT &aggrCalc); + static void recalc(InternalNodeType &node, const NodeAllocatorType &allocator, const AggrCalcT &aggrCalc); + static AggregatedType recalc(LeafNodeType &node, LeafNodeType &splitNode, const AggrCalcT &aggrCalc); - static AggregatedType - recalc(InternalNodeType &node, - InternalNodeType &splitNode, - const NodeAllocatorType &allocator, - const AggrCalcT &aggrCalc); + static AggregatedType recalc(InternalNodeType &node, InternalNodeType &splitNode, + const NodeAllocatorType &allocator, const AggrCalcT &aggrCalc); }; -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreeaggregator.hpp b/searchlib/src/vespa/searchlib/btree/btreeaggregator.hpp index 5a424fb55ff..e1318ab5a66 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeaggregator.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreeaggregator.hpp @@ -4,11 +4,7 @@ #include "btreeaggregator.h" -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename KeyT, typename DataT, typename AggrT, size_t INTERNAL_SLOTS, size_t LEAF_SLOTS, class AggrCalcT> @@ -93,7 +89,4 @@ BTreeAggregator<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, AggrCalcT>:: return a; } - -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreebuilder.cpp b/searchlib/src/vespa/searchlib/btree/btreebuilder.cpp index c07000090dc..133c5d245c9 100644 --- a/searchlib/src/vespa/searchlib/btree/btreebuilder.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreebuilder.cpp @@ -1,21 +1,17 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "btreebuilder.h" #include "btreenode.hpp" #include "btreebuilder.hpp" namespace search::btree { -template class BTreeBuilder<uint32_t, uint32_t, - NoAggregated, +template class BTreeBuilder<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeBuilder<uint32_t, BTreeNoLeafData, - NoAggregated, +template class BTreeBuilder<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeBuilder<uint32_t, int32_t, - MinMaxAggregated, +template class BTreeBuilder<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS, MinMaxAggrCalc>; diff --git a/searchlib/src/vespa/searchlib/btree/btreebuilder.h b/searchlib/src/vespa/searchlib/btree/btreebuilder.h index 4527bbf4fb8..767f02d03ee 100644 --- a/searchlib/src/vespa/searchlib/btree/btreebuilder.h +++ b/searchlib/src/vespa/searchlib/btree/btreebuilder.h @@ -9,11 +9,7 @@ #include "minmaxaggrcalc.h" #include "btreeaggregator.h" -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename KeyT, typename DataT, @@ -24,21 +20,17 @@ template <typename KeyT, class BTreeBuilder { public: - typedef BTreeNodeAllocator<KeyT, DataT, AggrT, - INTERNAL_SLOTS, LEAF_SLOTS> NodeAllocatorType; - typedef typename NodeAllocatorType::BTreeRootBaseType BTreeRootBaseType; - typedef typename NodeAllocatorType::InternalNodeType InternalNodeType; - typedef typename NodeAllocatorType::LeafNodeType LeafNodeType; - typedef BTreeAggregator<KeyT, DataT, AggrT, - INTERNAL_SLOTS, - LEAF_SLOTS, - AggrCalcT> Aggregator; + using NodeAllocatorType = BTreeNodeAllocator<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>; + using BTreeRootBaseType = typename NodeAllocatorType::BTreeRootBaseType; + using InternalNodeType = typename NodeAllocatorType::InternalNodeType; + using LeafNodeType = typename NodeAllocatorType::LeafNodeType; + using Aggregator = BTreeAggregator<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, AggrCalcT>; private: - typedef KeyT KeyType; - typedef DataT DataType; - typedef typename InternalNodeType::RefPair InternalNodeTypeRefPair; - typedef typename LeafNodeType::RefPair LeafNodeTypeRefPair; - typedef BTreeNode::Ref NodeRef; + using KeyType = KeyT; + using DataType = DataT; + using InternalNodeTypeRefPair = typename InternalNodeType::RefPair; + using LeafNodeTypeRefPair = typename LeafNodeType::RefPair; + using NodeRef = BTreeNode::Ref; NodeAllocatorType &_allocator; int _numInternalNodes; @@ -49,52 +41,30 @@ private: AggrCalcT _defaultAggrCalc; const AggrCalcT &_aggrCalc; - void - normalize(); - - void - allocNewLeafNode(); - - InternalNodeType * - createInternalNode(); + void normalize(); + void allocNewLeafNode(); + InternalNodeType *createInternalNode(); public: BTreeBuilder(NodeAllocatorType &allocator); - BTreeBuilder(NodeAllocatorType &allocator, const AggrCalcT &aggrCalc); - ~BTreeBuilder(); - void - recursiveDelete(NodeRef node); - - void - insert(const KeyT &key, const DataT &data); - - NodeRef - handover(); - - void - reuse(); - - void - clear(); + void recursiveDelete(NodeRef node); + void insert(const KeyT &key, const DataT &data); + NodeRef handover(); + void reuse(); + void clear(); }; -extern template class BTreeBuilder<uint32_t, uint32_t, - NoAggregated, +extern template class BTreeBuilder<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeBuilder<uint32_t, BTreeNoLeafData, - NoAggregated, +extern template class BTreeBuilder<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeBuilder<uint32_t, int32_t, - MinMaxAggregated, +extern template class BTreeBuilder<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS, MinMaxAggrCalc>; -} // namespace btree - -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreebuilder.hpp b/searchlib/src/vespa/searchlib/btree/btreebuilder.hpp index 0816f80826c..fb912499c6c 100644 --- a/searchlib/src/vespa/searchlib/btree/btreebuilder.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreebuilder.hpp @@ -4,11 +4,7 @@ #include "btreebuilder.h" -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename KeyT, typename DataT, typename AggrT, size_t INTERNAL_SLOTS, size_t LEAF_SLOTS, class AggrCalcT> @@ -450,8 +446,4 @@ clear() assert(_numInternalNodes == 0); } - -} // namespace btree - -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreeiterator.cpp b/searchlib/src/vespa/searchlib/btree/btreeiterator.cpp index 08ad4345289..9444cee975d 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeiterator.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreeiterator.cpp @@ -6,9 +6,6 @@ #include "btreeiterator.hpp" #include "btreenode.hpp" -#include <vespa/log/log.h> -LOG_SETUP(".searchlib.btree.breeiterator"); - namespace search::btree { template class BTreeIteratorBase<uint32_t, uint32_t, NoAggregated>; diff --git a/searchlib/src/vespa/searchlib/btree/btreeiterator.h b/searchlib/src/vespa/searchlib/btree/btreeiterator.h index 3955a4de27c..de9637c00f1 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeiterator.h +++ b/searchlib/src/vespa/searchlib/btree/btreeiterator.h @@ -7,8 +7,7 @@ #include "btreetraits.h" #include <vespa/fastos/dynamiclibrary.h> -namespace search { -namespace btree { +namespace search::btree { template <typename, typename, typename, typename, typename, class> class BTreeInserter; @@ -871,21 +870,15 @@ private: void adjustGivenEntriesToRightLeafNode(); }; - extern template class BTreeIteratorBase<uint32_t, uint32_t, NoAggregated>; -extern template class BTreeIteratorBase<uint32_t, BTreeNoLeafData, - NoAggregated>; -extern template class BTreeIteratorBase<uint32_t, int32_t, - MinMaxAggregated>; +extern template class BTreeIteratorBase<uint32_t, BTreeNoLeafData, NoAggregated>; +extern template class BTreeIteratorBase<uint32_t, int32_t, MinMaxAggregated>; extern template class BTreeConstIterator<uint32_t, uint32_t, NoAggregated>; -extern template class BTreeConstIterator<uint32_t, BTreeNoLeafData, - NoAggregated>; -extern template class BTreeConstIterator<uint32_t, int32_t, - MinMaxAggregated>; +extern template class BTreeConstIterator<uint32_t, BTreeNoLeafData, NoAggregated>; +extern template class BTreeConstIterator<uint32_t, int32_t, MinMaxAggregated>; extern template class BTreeIterator<uint32_t, uint32_t, NoAggregated>; extern template class BTreeIterator<uint32_t, BTreeNoLeafData, NoAggregated>; extern template class BTreeIterator<uint32_t, int32_t, MinMaxAggregated>; -} // namespace search::btree -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/btree/btreeiterator.hpp b/searchlib/src/vespa/searchlib/btree/btreeiterator.hpp index 02b73ef53f6..b26f249c51b 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeiterator.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreeiterator.hpp @@ -6,26 +6,11 @@ #include "btreeaggregator.h" #include "btreenode.hpp" #include <vespa/vespalib/util/hdr_abort.h> -#include <vespa/vespalib/stllike/asciistream.h> -namespace search { -namespace btree { +namespace search::btree { #define STRICT_BTREE_ITERATOR_SEEK -namespace { - -template <typename KeyT> -vespalib::string -keyToStr(const KeyT & key) -{ - vespalib::asciistream ss; - ss << key; - return ss.str(); -} - -} - template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: @@ -1373,6 +1358,4 @@ BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>::adjustGivenEntriesToRightL } } -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreenode.cpp b/searchlib/src/vespa/searchlib/btree/btreenode.cpp index a47c9de77b4..b3d7b60adb6 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenode.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreenode.cpp @@ -1,14 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "btreenode.h" #include "btreenode.hpp" namespace search::btree { NoAggregated BTreeNodeAggregatedWrap<NoAggregated>::_instance; + template <> -MinMaxAggregated BTreeNodeAggregatedWrap<MinMaxAggregated>::_instance = - MinMaxAggregated(); +MinMaxAggregated BTreeNodeAggregatedWrap<MinMaxAggregated>::_instance = MinMaxAggregated(); template class BTreeNodeDataWrap<uint32_t, 16>; template class BTreeNodeDataWrap<BTreeNoLeafData, 16>; @@ -23,8 +22,7 @@ template class BTreeLeafNode<uint32_t, uint32_t, NoAggregated, 16>; template class BTreeLeafNode<uint32_t, BTreeNoLeafData, NoAggregated, 16>; template class BTreeLeafNode<uint32_t, int32_t, MinMaxAggregated, 16>; template class BTreeLeafNodeTemp<uint32_t, uint32_t, NoAggregated, 16>; -template class BTreeLeafNodeTemp<uint32_t, int32_t, MinMaxAggregated, - 16>; +template class BTreeLeafNodeTemp<uint32_t, int32_t, MinMaxAggregated, 16>; template class BTreeLeafNodeTemp<uint32_t, BTreeNoLeafData, NoAggregated, 16>; } // namespace search::btree diff --git a/searchlib/src/vespa/searchlib/btree/btreenode.h b/searchlib/src/vespa/searchlib/btree/btreenode.h index d0f5d3a0ee2..7302b4d5203 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenode.h +++ b/searchlib/src/vespa/searchlib/btree/btreenode.h @@ -4,15 +4,14 @@ #include "noaggregated.h" #include "minmaxaggregated.h" +#include "btree_key_data.h" #include <vespa/searchlib/datastore/entryref.h> #include <vespa/searchlib/datastore/handle.h> #include <cassert> #include <utility> #include <cstddef> -#include "btree_key_data.h" -namespace search { -namespace datastore { +namespace search::datastore { template <typename, typename> class Allocator; template <typename> class BufferType; @@ -23,7 +22,7 @@ template <typename, typename ...> class Assigner; } -namespace btree { +namespace search::btree { template <typename, typename, typename, size_t, size_t> class BTreeNodeAllocator; template <typename, typename, typename, size_t, size_t> class BTreeNodeStore; @@ -506,5 +505,4 @@ extern template class BTreeLeafNodeTemp<uint32_t, int32_t, MinMaxAggregated, extern template class BTreeLeafNodeTemp<uint32_t, BTreeNoLeafData, NoAggregated, 16>; -} // namespace search::btree -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/btree/btreenode.hpp b/searchlib/src/vespa/searchlib/btree/btreenode.hpp index 3523641705b..dbf926a302c 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenode.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreenode.hpp @@ -5,8 +5,7 @@ #include "btreenode.h" #include <algorithm> -namespace search { -namespace btree { +namespace search::btree { namespace { @@ -381,7 +380,4 @@ BTreeLeafNode(const KeyDataType *smallArray, uint32_t arraySize) freeze(); } - -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.cpp b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.cpp index 9753e39a1d3..1a05d68b04f 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.cpp @@ -1,27 +1,20 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "btreenodeallocator.h" #include "btreenodeallocator.hpp" #include <vespa/vespalib/util/array.hpp> template class vespalib::Array<search::datastore::EntryRef>; -namespace search { -namespace btree { +namespace search::btree { -template class BTreeNodeAllocator<uint32_t, uint32_t, - NoAggregated, +template class BTreeNodeAllocator<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeNodeAllocator<uint32_t, BTreeNoLeafData, - NoAggregated, +template class BTreeNodeAllocator<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeNodeAllocator<uint32_t, int32_t, - MinMaxAggregated, +template class BTreeNodeAllocator<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -} // namespace btree - -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h index 6d4b381ee28..46eca13823b 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h +++ b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.h @@ -2,21 +2,15 @@ #pragma once -#include <vector> -#include <deque> - #include "btreenode.h" -#include <vespa/vespalib/util/generationhandler.h> -#include <vespa/searchlib/util/memoryusage.h> #include "btreenodestore.h" #include <vespa/vespalib/stllike/string.h> #include <vespa/vespalib/util/array.h> +#include <vespa/vespalib/util/generationhandler.h> +#include <vespa/searchlib/util/memoryusage.h> +#include <vector> -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename, typename, typename, size_t, size_t> class BTreeRootBase; @@ -28,23 +22,20 @@ template <typename KeyT, class BTreeNodeAllocator { public: - typedef BTreeInternalNode<KeyT, AggrT, INTERNAL_SLOTS> InternalNodeType; - typedef BTreeLeafNode<KeyT, DataT, AggrT, LEAF_SLOTS> LeafNodeType; - typedef typename InternalNodeType::RefPair InternalNodeTypeRefPair; - typedef typename LeafNodeType::RefPair LeafNodeTypeRefPair; - typedef BTreeRootBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS> - BTreeRootBaseType; - typedef vespalib::GenerationHandler::generation_t generation_t; - typedef BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS> - NodeStore; + using InternalNodeType = BTreeInternalNode<KeyT, AggrT, INTERNAL_SLOTS>; + using LeafNodeType = BTreeLeafNode<KeyT, DataT, AggrT, LEAF_SLOTS>; + using InternalNodeTypeRefPair = typename InternalNodeType::RefPair; + using LeafNodeTypeRefPair = typename LeafNodeType::RefPair; + using BTreeRootBaseType = BTreeRootBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>; + using generation_t = vespalib::GenerationHandler::generation_t; + using NodeStore = BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>; using EntryRef = datastore::EntryRef; using DataStoreBase = datastore::DataStoreBase; private: BTreeNodeAllocator(const BTreeNodeAllocator &rhs); - BTreeNodeAllocator & - operator=(const BTreeNodeAllocator &rhs); + BTreeNodeAllocator & operator=(const BTreeNodeAllocator &rhs); NodeStore _nodeStore; @@ -62,71 +53,54 @@ private: public: BTreeNodeAllocator(); - ~BTreeNodeAllocator(); - void - disableFreeLists() { + void disableFreeLists() { _nodeStore.disableFreeLists(); } - void - disableElemHoldList() - { + void disableElemHoldList() { _nodeStore.disableElemHoldList(); } /** * Allocate internal node. */ - InternalNodeTypeRefPair - allocInternalNode(uint8_t level); + InternalNodeTypeRefPair allocInternalNode(uint8_t level); /* * Allocate leaf node. */ - LeafNodeTypeRefPair - allocLeafNode(); - - InternalNodeTypeRefPair - thawNode(BTreeNode::Ref nodeRef, InternalNodeType *node); - - LeafNodeTypeRefPair - thawNode(BTreeNode::Ref nodeRef, LeafNodeType *node); - - BTreeNode::Ref - thawNode(BTreeNode::Ref node); + LeafNodeTypeRefPair allocLeafNode(); + InternalNodeTypeRefPair thawNode(BTreeNode::Ref nodeRef, InternalNodeType *node); + LeafNodeTypeRefPair thawNode(BTreeNode::Ref nodeRef, LeafNodeType *node); + BTreeNode::Ref thawNode(BTreeNode::Ref node); /** * hold internal node until freeze/generation constraint is satisfied. */ - void - holdNode(BTreeNode::Ref nodeRef, InternalNodeType *node); + void holdNode(BTreeNode::Ref nodeRef, InternalNodeType *node); /** * hold leaf node until freeze/generation constraint is satisfied. */ - void - holdNode(BTreeNode::Ref nodeRef, LeafNodeType *node); + void holdNode(BTreeNode::Ref nodeRef, LeafNodeType *node); /** * Mark that tree needs to be frozen. Tree must be kept alive until * freeze operation has completed. */ - void - needFreeze(BTreeRootBaseType *tree); + void needFreeze(BTreeRootBaseType *tree); /** * Freeze all nodes that are not already frozen. */ - void - freeze(); + void freeze(); /** * Try to free held nodes if nobody can be referencing them. */ - void - trimHoldLists(generation_t usedGen); + void trimHoldLists(generation_t usedGen); /** * Transfer nodes from hold1 lists to hold2 lists, they are no @@ -134,140 +108,89 @@ public: * older versions of the frozen structure must leave before elements * can be unheld. */ - void - transferHoldLists(generation_t generation); + void transferHoldLists(generation_t generation); - void - clearHoldLists(); + void clearHoldLists(); - static bool - isValidRef(BTreeNode::Ref ref) - { - return NodeStore::isValidRef(ref); - } + static bool isValidRef(BTreeNode::Ref ref) { return NodeStore::isValidRef(ref); } - bool - isLeafRef(BTreeNode::Ref ref) const - { + bool isLeafRef(BTreeNode::Ref ref) const { if (!isValidRef(ref)) return false; return _nodeStore.isLeafRef(ref); } - const InternalNodeType * - mapInternalRef(BTreeNode::Ref ref) const - { + const InternalNodeType *mapInternalRef(BTreeNode::Ref ref) const { return _nodeStore.mapInternalRef(ref); } - InternalNodeType * - mapInternalRef(BTreeNode::Ref ref) - { + InternalNodeType *mapInternalRef(BTreeNode::Ref ref) { return _nodeStore.mapInternalRef(ref); } - const LeafNodeType * - mapLeafRef(BTreeNode::Ref ref) const - { + const LeafNodeType *mapLeafRef(BTreeNode::Ref ref) const { return _nodeStore.mapLeafRef(ref); } - LeafNodeType * - mapLeafRef(BTreeNode::Ref ref) - { + LeafNodeType *mapLeafRef(BTreeNode::Ref ref) { return _nodeStore.mapLeafRef(ref); } template <typename NodeType> - const NodeType * - mapRef(BTreeNode::Ref ref) const - { + const NodeType *mapRef(BTreeNode::Ref ref) const { return _nodeStore.template mapRef<NodeType>(ref); } template <typename NodeType> - NodeType * - mapRef(BTreeNode::Ref ref) - { + NodeType *mapRef(BTreeNode::Ref ref) { return _nodeStore.template mapRef<NodeType>(ref); } - InternalNodeTypeRefPair - moveInternalNode(const InternalNodeType *node); - - LeafNodeTypeRefPair - moveLeafNode(const LeafNodeType *node); - - uint32_t - validLeaves(BTreeNode::Ref ref) const; + InternalNodeTypeRefPair moveInternalNode(const InternalNodeType *node); + LeafNodeTypeRefPair moveLeafNode(const LeafNodeType *node); + uint32_t validLeaves(BTreeNode::Ref ref) const; /* * Extract level from ref. */ - uint32_t - getLevel(BTreeNode::Ref ref) const; - - const KeyT & - getLastKey(BTreeNode::Ref node) const; - - const AggrT & - getAggregated(BTreeNode::Ref node) const; + uint32_t getLevel(BTreeNode::Ref ref) const; + const KeyT &getLastKey(BTreeNode::Ref node) const; + const AggrT &getAggregated(BTreeNode::Ref node) const; MemoryUsage getMemoryUsage() const; vespalib::string toString(BTreeNode::Ref ref) const; - vespalib::string toString(const BTreeNode * node) const; - bool - getCompacting(EntryRef ref) const - { - return _nodeStore.getCompacting(ref); - } - - std::vector<uint32_t> - startCompact() - { - return _nodeStore.startCompact(); - } + bool getCompacting(EntryRef ref) const { return _nodeStore.getCompacting(ref); } + std::vector<uint32_t> startCompact() { return _nodeStore.startCompact(); } - void - finishCompact(const std::vector<uint32_t> &toHold) - { + void finishCompact(const std::vector<uint32_t> &toHold) { return _nodeStore.finishCompact(toHold); } template <typename FunctionType> - void - foreach_key(EntryRef ref, FunctionType func) const - { + void foreach_key(EntryRef ref, FunctionType func) const { _nodeStore.foreach_key(ref, func); } template <typename FunctionType> - void - foreach(EntryRef ref, FunctionType func) const - { + void foreach(EntryRef ref, FunctionType func) const { _nodeStore.foreach(ref, func); } const NodeStore &getNodeStore() const { return _nodeStore; } }; -extern template class BTreeNodeAllocator<uint32_t, uint32_t, - NoAggregated, +extern template class BTreeNodeAllocator<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeNodeAllocator<uint32_t, BTreeNoLeafData, - NoAggregated, +extern template class BTreeNodeAllocator<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeNodeAllocator<uint32_t, int32_t, - MinMaxAggregated, +extern template class BTreeNodeAllocator<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -} // namespace btree - -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.hpp b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.hpp index 4ea2035c73a..1a0df9e397b 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenodeallocator.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreenodeallocator.hpp @@ -8,8 +8,7 @@ #include <vespa/vespalib/util/array.hpp> #include "btreenodestore.hpp" -namespace search { -namespace btree { +namespace search::btree { template <typename KeyT, typename DataT, typename AggrT, size_t INTERNAL_SLOTS, size_t LEAF_SLOTS> @@ -432,7 +431,4 @@ toString(const BTreeNode * node) const return ss.str(); } - -} // namespace btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreenodestore.cpp b/searchlib/src/vespa/searchlib/btree/btreenodestore.cpp index 4408e59b610..bfb1e2fa6a1 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenodestore.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreenodestore.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "btreenodestore.hpp" -#include "btreenode.h" #include "btreerootbase.h" #include "btreeroot.h" #include "btreenodeallocator.h" @@ -9,28 +8,14 @@ namespace search::btree { -template class BTreeNodeStore<uint32_t, uint32_t, - NoAggregated, +template class BTreeNodeStore<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeNodeStore<uint32_t, BTreeNoLeafData, - NoAggregated, +template class BTreeNodeStore<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeNodeStore<uint32_t, int32_t, - MinMaxAggregated, +template class BTreeNodeStore<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; - -typedef BTreeNodeStore<uint32_t, uint32_t, NoAggregated, - BTreeDefaultTraits::INTERNAL_SLOTS, - BTreeDefaultTraits::LEAF_SLOTS> MyNodeStore1; -typedef BTreeNodeStore<uint32_t, BTreeNoLeafData, NoAggregated, - BTreeDefaultTraits::INTERNAL_SLOTS, - BTreeDefaultTraits::LEAF_SLOTS> MyNodeStore2; -typedef BTreeNodeStore<uint32_t, int32_t, MinMaxAggregated, - BTreeDefaultTraits::INTERNAL_SLOTS, - BTreeDefaultTraits::LEAF_SLOTS> MyNodeStore3; - } diff --git a/searchlib/src/vespa/searchlib/btree/btreenodestore.h b/searchlib/src/vespa/searchlib/btree/btreenodestore.h index 7c818f30c00..00f5f5e8e70 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenodestore.h +++ b/searchlib/src/vespa/searchlib/btree/btreenodestore.h @@ -6,17 +6,12 @@ #include "btreetraits.h" #include <vespa/searchlib/datastore/datastore.h> -namespace search -{ - -namespace btree -{ +namespace search::btree { class BTreeNodeReclaimer { public: - static void reclaim(BTreeNode * node) - { + static void reclaim(BTreeNode * node) { node->unFreeze(); } }; @@ -30,18 +25,15 @@ class BTreeNodeBufferType : public datastore::BufferType<EntryType> using ParentType::_clusterSize; using CleanContext = typename ParentType::CleanContext; public: - BTreeNodeBufferType(uint32_t minClusters, - uint32_t maxClusters) + BTreeNodeBufferType(uint32_t minClusters, uint32_t maxClusters) : ParentType(1, minClusters, maxClusters) { _emptyEntry.freeze(); } - virtual void - initializeReservedElements(void *buffer, size_t reservedElements) override; + void initializeReservedElements(void *buffer, size_t reservedElements) override; - virtual void - cleanHold(void *buffer, uint64_t offset, uint64_t len, CleanContext cleanCtx) override; + void cleanHold(void *buffer, uint64_t offset, uint64_t len, CleanContext cleanCtx) override; }; @@ -80,141 +72,93 @@ public: ~BTreeNodeStore(); - void - disableFreeLists() { - _store.disableFreeLists(); - } + void disableFreeLists() { _store.disableFreeLists(); } + void disableElemHoldList() { _store.disableElemHoldList(); } - void - disableElemHoldList() - { - _store.disableElemHoldList(); - } + static bool isValidRef(EntryRef ref) { return ref.valid(); } - static bool - isValidRef(EntryRef ref) - { - return ref.valid(); - } - - bool - isLeafRef(EntryRef ref) const - { + bool isLeafRef(EntryRef ref) const { RefType iRef(ref); return _store.getTypeId(iRef.bufferId()) == NODETYPE_LEAF; } - const InternalNodeType * - mapInternalRef(EntryRef ref) const - { + const InternalNodeType *mapInternalRef(EntryRef ref) const { RefType iRef(ref); - return _store.getBufferEntry<InternalNodeType>(iRef.bufferId(), - iRef.offset()); + return _store.getBufferEntry<InternalNodeType>(iRef.bufferId(), iRef.offset()); } - InternalNodeType * - mapInternalRef(EntryRef ref) - { + InternalNodeType *mapInternalRef(EntryRef ref) { RefType iRef(ref); - return _store.getBufferEntry<InternalNodeType>(iRef.bufferId(), - iRef.offset()); + return _store.getBufferEntry<InternalNodeType>(iRef.bufferId(), iRef.offset()); } - const LeafNodeType * - mapLeafRef(EntryRef ref) const - { + const LeafNodeType *mapLeafRef(EntryRef ref) const { RefType iRef(ref); - return _store.getBufferEntry<LeafNodeType>(iRef.bufferId(), - iRef.offset()); + return _store.getBufferEntry<LeafNodeType>(iRef.bufferId(), iRef.offset()); } - LeafNodeType * - mapLeafRef(EntryRef ref) - { + LeafNodeType *mapLeafRef(EntryRef ref) { RefType iRef(ref); - return _store.getBufferEntry<LeafNodeType>(iRef.bufferId(), - iRef.offset()); + return _store.getBufferEntry<LeafNodeType>(iRef.bufferId(), iRef.offset()); } template <typename NodeType> - const NodeType * - mapRef(EntryRef ref) const - { + const NodeType *mapRef(EntryRef ref) const { RefType iRef(ref); - return _store.getBufferEntry<NodeType>(iRef.bufferId(), - iRef.offset()); + return _store.getBufferEntry<NodeType>(iRef.bufferId(), iRef.offset()); } template <typename NodeType> - NodeType * - mapRef(EntryRef ref) - { + NodeType *mapRef(EntryRef ref) { RefType iRef(ref); - return _store.getBufferEntry<NodeType>(iRef.bufferId(), - iRef.offset()); + return _store.getBufferEntry<NodeType>(iRef.bufferId(), iRef.offset()); } - LeafNodeTypeRefPair - allocNewLeafNode() { + LeafNodeTypeRefPair allocNewLeafNode() { return _store.allocator<LeafNodeType>(NODETYPE_LEAF).alloc(); } - LeafNodeTypeRefPair - allocLeafNode() { + LeafNodeTypeRefPair allocLeafNode() { return _store.freeListAllocator<LeafNodeType, BTreeNodeReclaimer>(NODETYPE_LEAF).alloc(); } - LeafNodeTypeRefPair - allocNewLeafNodeCopy(const LeafNodeType &rhs) { + LeafNodeTypeRefPair allocNewLeafNodeCopy(const LeafNodeType &rhs) { return _store.allocator<LeafNodeType>(NODETYPE_LEAF).alloc(rhs); } - LeafNodeTypeRefPair - allocLeafNodeCopy(const LeafNodeType &rhs) { + LeafNodeTypeRefPair allocLeafNodeCopy(const LeafNodeType &rhs) { return _store.freeListAllocator<LeafNodeType, BTreeNodeReclaimer>(NODETYPE_LEAF).alloc(rhs); } - InternalNodeTypeRefPair - allocNewInternalNode() { + InternalNodeTypeRefPair allocNewInternalNode() { return _store.allocator<InternalNodeType>(NODETYPE_INTERNAL).alloc(); } - InternalNodeTypeRefPair - allocInternalNode() { + InternalNodeTypeRefPair allocInternalNode() { return _store.freeListAllocator<InternalNodeType, BTreeNodeReclaimer>(NODETYPE_INTERNAL).alloc(); } - InternalNodeTypeRefPair - allocNewInternalNodeCopy(const InternalNodeType &rhs) { + InternalNodeTypeRefPair allocNewInternalNodeCopy(const InternalNodeType &rhs) { return _store.allocator<InternalNodeType>(NODETYPE_INTERNAL).alloc(rhs); } - InternalNodeTypeRefPair - allocInternalNodeCopy(const InternalNodeType &rhs) { + InternalNodeTypeRefPair allocInternalNodeCopy(const InternalNodeType &rhs) { return _store.freeListAllocator<InternalNodeType, BTreeNodeReclaimer>(NODETYPE_INTERNAL).alloc(rhs); } - void - holdElem(EntryRef ref) - { + void holdElem(EntryRef ref) { _store.holdElem(ref, 1); } - void - freeElem(EntryRef ref) - { + void freeElem(EntryRef ref) { _store.freeElem(ref, 1); } - std::vector<uint32_t> - startCompact(); + std::vector<uint32_t> startCompact(); - void - finishCompact(const std::vector<uint32_t> &toHold); + void finishCompact(const std::vector<uint32_t> &toHold); - void - transferHoldLists(generation_t generation) - { + void transferHoldLists(generation_t generation) { _store.transferHoldLists(generation); } @@ -224,15 +168,11 @@ public: } // Inherit doc from DataStoreBase - void - trimHoldLists(generation_t usedGen) - { + void trimHoldLists(generation_t usedGen) { _store.trimHoldLists(usedGen); } - void - clearHoldLists() - { + void clearHoldLists() { _store.clearHoldLists(); } @@ -247,9 +187,7 @@ public: } template <typename FunctionType> - void - foreach_key(EntryRef ref, FunctionType func) const - { + void foreach_key(EntryRef ref, FunctionType func) const { if (!ref.valid()) return; if (isLeafRef(ref)) { @@ -260,9 +198,7 @@ public: } template <typename FunctionType> - void - foreach(EntryRef ref, FunctionType func) const - { + void foreach(EntryRef ref, FunctionType func) const { if (!ref.valid()) return; if (isLeafRef(ref)) { @@ -273,20 +209,14 @@ public: } }; -extern template class BTreeNodeStore<uint32_t, uint32_t, - NoAggregated, +extern template class BTreeNodeStore<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeNodeStore<uint32_t, BTreeNoLeafData, - NoAggregated, +extern template class BTreeNodeStore<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeNodeStore<uint32_t, int32_t, - MinMaxAggregated, +extern template class BTreeNodeStore<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -} // namespace btree - -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreenodestore.hpp b/searchlib/src/vespa/searchlib/btree/btreenodestore.hpp index 2d16ecece8a..d005e9d7e3a 100644 --- a/searchlib/src/vespa/searchlib/btree/btreenodestore.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreenodestore.hpp @@ -5,11 +5,7 @@ #include "btreenodestore.h" #include <vespa/searchlib/datastore/datastore.hpp> -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename EntryType> void @@ -26,10 +22,7 @@ BTreeNodeBufferType<EntryType>::initializeReservedElements(void *buffer, size_t template <typename EntryType> void -BTreeNodeBufferType<EntryType>::cleanHold(void *buffer, - uint64_t offset, - uint64_t len, - CleanContext) +BTreeNodeBufferType<EntryType>::cleanHold(void *buffer, uint64_t offset, uint64_t len, CleanContext) { EntryType *e = static_cast<EntryType *>(buffer) + offset; for (size_t j = len; j != 0; --j) { @@ -70,14 +63,10 @@ std::vector<uint32_t> BTreeNodeStore<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>:: startCompact() { - std::vector<uint32_t> iToHold = - _store.startCompact(NODETYPE_INTERNAL); - std::vector<uint32_t> lToHold = - _store.startCompact(NODETYPE_LEAF); + std::vector<uint32_t> iToHold = _store.startCompact(NODETYPE_INTERNAL); + std::vector<uint32_t> lToHold = _store.startCompact(NODETYPE_LEAF); std::vector<uint32_t> ret = iToHold; - for (std::vector<uint32_t>::const_iterator - i = lToHold.begin(), ie = lToHold.end(); i != ie; ++i) - ret.push_back(*i); + ret.insert(ret.end(), lToHold.begin(), lToHold.end()); return ret; } @@ -91,9 +80,4 @@ finishCompact(const std::vector<uint32_t> &toHold) _store.finishCompact(toHold); } - -} // namespace btree - -} // namespace search - - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreeroot.cpp b/searchlib/src/vespa/searchlib/btree/btreeroot.cpp index 60c44f7973e..a576b6ce1e0 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeroot.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreeroot.cpp @@ -6,9 +6,6 @@ #include "btreeroot.hpp" #include "btreenode.hpp" -#include <vespa/log/log.h> -LOG_SETUP(".searchlib.btree.btreeroot"); - namespace search::btree { template class BTreeRootT<uint32_t, uint32_t, NoAggregated>; @@ -16,8 +13,6 @@ template class BTreeRootT<uint32_t, BTreeNoLeafData, NoAggregated>; template class BTreeRootT<uint32_t, int32_t, MinMaxAggregated>; template class BTreeRoot<uint32_t, uint32_t, NoAggregated>; template class BTreeRoot<uint32_t, BTreeNoLeafData, NoAggregated>; -template class BTreeRoot<uint32_t, int32_t, MinMaxAggregated, - std::less<uint32_t>, - BTreeDefaultTraits, MinMaxAggrCalc>; +template class BTreeRoot<uint32_t, int32_t, MinMaxAggregated, std::less<uint32_t>, BTreeDefaultTraits, MinMaxAggrCalc>; } diff --git a/searchlib/src/vespa/searchlib/btree/btreeroot.h b/searchlib/src/vespa/searchlib/btree/btreeroot.h index 86dd47ca5fa..b5759a6a341 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeroot.h +++ b/searchlib/src/vespa/searchlib/btree/btreeroot.h @@ -9,8 +9,7 @@ #include "noaggrcalc.h" #include "minmaxaggrcalc.h" -namespace search { -namespace btree { +namespace search::btree { template <typename, typename, typename, size_t, size_t> class BTreeNodeAllocator; @@ -80,30 +79,17 @@ public: where.emplace_back(_frozenRoot, _allocator); } - BTreeNode::Ref - getRoot() const - { - return _frozenRoot; - } - - size_t - size() const; - - const NodeAllocatorType & - getAllocator() const - { - return _allocator; - } + BTreeNode::Ref getRoot() const { return _frozenRoot; } + size_t size() const; + const NodeAllocatorType &getAllocator() const { return _allocator; } template <typename FunctionType> - void - foreach_key(FunctionType func) const { + void foreach_key(FunctionType func) const { _allocator.getNodeStore().foreach_key(_frozenRoot, func); } template <typename FunctionType> - void - foreach(FunctionType func) const { + void foreach(FunctionType func) const { _allocator.getNodeStore().foreach(_frozenRoot, func); } }; @@ -123,20 +109,12 @@ public: BTreeRootT(); ~BTreeRootT(); - void - clear(NodeAllocatorType &allocator); - - Iterator - find(const KeyType & key, const NodeAllocatorType &allocator, - CompareT comp = CompareT()) const; + void clear(NodeAllocatorType &allocator); - Iterator - lowerBound(const KeyType & key, const NodeAllocatorType & allocator, - CompareT comp = CompareT()) const; + Iterator find(const KeyType & key, const NodeAllocatorType &allocator, CompareT comp = CompareT()) const; - Iterator - upperBound(const KeyType & key, const NodeAllocatorType & allocator, - CompareT comp = CompareT()) const; + Iterator lowerBound(const KeyType & key, const NodeAllocatorType & allocator, CompareT comp = CompareT()) const; + Iterator upperBound(const KeyType & key, const NodeAllocatorType & allocator, CompareT comp = CompareT()) const; Iterator begin(const NodeAllocatorType &allocator) const { return Iterator(_root, allocator); @@ -146,22 +124,12 @@ public: return FrozenView(getFrozenRoot(), allocator); } - size_t - size(const NodeAllocatorType &allocator) const; - - size_t - frozenSize(const NodeAllocatorType &allocator) const; - + size_t size(const NodeAllocatorType &allocator) const; + size_t frozenSize(const NodeAllocatorType &allocator) const; vespalib::string toString(const NodeAllocatorType &allocator) const; - - size_t - bitSize(const NodeAllocatorType &allocator) const; - - size_t - bitSize(BTreeNode::Ref node, const NodeAllocatorType &allocator) const; - - void - thaw(Iterator &itr); + size_t bitSize(const NodeAllocatorType &allocator) const; + size_t bitSize(BTreeNode::Ref node, const NodeAllocatorType &allocator) const; + void thaw(Iterator &itr); }; @@ -244,9 +212,6 @@ extern template class BTreeRootT<uint32_t, int32_t, MinMaxAggregated>; extern template class BTreeRoot<uint32_t, uint32_t, NoAggregated>; extern template class BTreeRoot<uint32_t, BTreeNoLeafData, NoAggregated>; extern template class BTreeRoot<uint32_t, int32_t, MinMaxAggregated, - std::less<uint32_t>, - BTreeDefaultTraits, MinMaxAggrCalc>; - -} // namespace search::btree -} // namespace search + std::less<uint32_t>, BTreeDefaultTraits, MinMaxAggrCalc>; +} diff --git a/searchlib/src/vespa/searchlib/btree/btreeroot.hpp b/searchlib/src/vespa/searchlib/btree/btreeroot.hpp index 365a52aa8de..22703f2dfd2 100644 --- a/searchlib/src/vespa/searchlib/btree/btreeroot.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreeroot.hpp @@ -10,8 +10,7 @@ #include "btreeaggregator.hpp" #include <vespa/vespalib/stllike/asciistream.h> -namespace search { -namespace btree { +namespace search::btree { //----------------------- BTreeRoot ------------------------------------------// @@ -235,16 +234,11 @@ FrozenView::size() const template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> -BTreeRootT<KeyT, DataT, AggrT, CompareT, TraitsT>::BTreeRootT() - : ParentType() -{ -} +BTreeRootT<KeyT, DataT, AggrT, CompareT, TraitsT>::BTreeRootT() = default; template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> -BTreeRootT<KeyT, DataT, AggrT, CompareT, TraitsT>::~BTreeRootT() -{ -} +BTreeRootT<KeyT, DataT, AggrT, CompareT, TraitsT>::~BTreeRootT() = default; template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> @@ -492,7 +486,4 @@ remove(Iterator &itr, itr.getAllocator().needFreeze(this); } - -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreerootbase.cpp b/searchlib/src/vespa/searchlib/btree/btreerootbase.cpp index 311cc3adf37..12394761bf9 100644 --- a/searchlib/src/vespa/searchlib/btree/btreerootbase.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreerootbase.cpp @@ -3,24 +3,16 @@ #include "btreerootbase.h" #include "btreerootbase.hpp" -namespace search -{ +namespace search::btree { -namespace btree -{ - -template class BTreeRootBase<uint32_t, uint32_t, - NoAggregated, +template class BTreeRootBase<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeRootBase<uint32_t, BTreeNoLeafData, - NoAggregated, +template class BTreeRootBase<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -template class BTreeRootBase<uint32_t, int32_t, - MinMaxAggregated, +template class BTreeRootBase<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -} // namespace btree -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/btree/btreerootbase.h b/searchlib/src/vespa/searchlib/btree/btreerootbase.h index 124928ba708..ed4889214ca 100644 --- a/searchlib/src/vespa/searchlib/btree/btreerootbase.h +++ b/searchlib/src/vespa/searchlib/btree/btreerootbase.h @@ -7,8 +7,7 @@ #include "btreenodeallocator.h" #include <atomic> -namespace search { -namespace btree { +namespace search::btree { template <typename KeyT, typename DataT, @@ -35,87 +34,62 @@ protected: "BTree root reference size mismatch"); BTreeRootBase(); - BTreeRootBase(const BTreeRootBase &rhs); - BTreeRootBase &operator=(const BTreeRootBase &rhs); - ~BTreeRootBase(); public: - void - freeze(NodeAllocatorType &allocator); + void freeze(NodeAllocatorType &allocator); bool isFrozen() const { return (_root.ref() == _frozenRoot.load(std::memory_order_relaxed)); } - void - setRoot(BTreeNode::Ref newRoot, NodeAllocatorType &allocator) - { + void setRoot(BTreeNode::Ref newRoot, NodeAllocatorType &allocator) { bool oldFrozen = isFrozen(); _root = newRoot; if (oldFrozen && !isFrozen()) allocator.needFreeze(this); } - void - setRoots(BTreeNode::Ref newRoot) - { + void setRoots(BTreeNode::Ref newRoot) { _root = newRoot; _frozenRoot = newRoot.ref(); } - BTreeNode::Ref - getRoot() const - { + BTreeNode::Ref getRoot() const { return _root; } - BTreeNode::Ref - getFrozenRoot() const - { + BTreeNode::Ref getFrozenRoot() const { return BTreeNode::Ref(_frozenRoot.load(std::memory_order_acquire)); } - BTreeNode::Ref - getFrozenRootRelaxed() const - { + BTreeNode::Ref getFrozenRootRelaxed() const { return BTreeNode::Ref(_frozenRoot.load(std::memory_order_relaxed)); } - const AggrT & - getAggregated(const NodeAllocatorType &allocator) const - { + const AggrT &getAggregated(const NodeAllocatorType &allocator) const { return allocator.getAggregated(_root); } - void - recycle() - { + void recycle() { _root = BTreeNode::Ref(); _frozenRoot = BTreeNode::Ref().ref(); } protected: - void - recursiveDelete(BTreeNode::Ref node, NodeAllocatorType &allocator); + void recursiveDelete(BTreeNode::Ref node, NodeAllocatorType &allocator); }; -extern template class BTreeRootBase<uint32_t, uint32_t, - NoAggregated, +extern template class BTreeRootBase<uint32_t, uint32_t, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeRootBase<uint32_t, BTreeNoLeafData, - NoAggregated, +extern template class BTreeRootBase<uint32_t, BTreeNoLeafData, NoAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -extern template class BTreeRootBase<uint32_t, int32_t, - MinMaxAggregated, +extern template class BTreeRootBase<uint32_t, int32_t, MinMaxAggregated, BTreeDefaultTraits::INTERNAL_SLOTS, BTreeDefaultTraits::LEAF_SLOTS>; -} // namespace btree -} // namespace search - - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreerootbase.hpp b/searchlib/src/vespa/searchlib/btree/btreerootbase.hpp index 238dad266c5..0b4ef18aad9 100644 --- a/searchlib/src/vespa/searchlib/btree/btreerootbase.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreerootbase.hpp @@ -4,9 +4,7 @@ #include "btreerootbase.h" -namespace search { -namespace btree { - +namespace search::btree { template <typename KeyT, typename DataT, typename AggrT, size_t INTERNAL_SLOTS, size_t LEAF_SLOTS> @@ -70,8 +68,7 @@ template <typename KeyT, typename DataT, typename AggrT, size_t INTERNAL_SLOTS, size_t LEAF_SLOTS> void BTreeRootBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS>:: -recursiveDelete(BTreeNode::Ref node, - NodeAllocatorType &allocator) +recursiveDelete(BTreeNode::Ref node, NodeAllocatorType &allocator) { assert(allocator.isValidRef(node)); if (!allocator.isLeafRef(node)) { @@ -85,6 +82,4 @@ recursiveDelete(BTreeNode::Ref node, } } -} // namespace btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/btreestore.cpp b/searchlib/src/vespa/searchlib/btree/btreestore.cpp index 4467aad15d5..bead11295b3 100644 --- a/searchlib/src/vespa/searchlib/btree/btreestore.cpp +++ b/searchlib/src/vespa/searchlib/btree/btreestore.cpp @@ -4,25 +4,10 @@ #include "btreestore.hpp" #include "btreeiterator.hpp" -#include <vespa/log/log.h> -LOG_SETUP(".searchlib.btree.breestore"); - namespace search::btree { -template class BTreeStore<uint32_t, uint32_t, - NoAggregated, - std::less<uint32_t>, - BTreeDefaultTraits>; - -template class BTreeStore<uint32_t, BTreeNoLeafData, - NoAggregated, - std::less<uint32_t>, - BTreeDefaultTraits>; - -template class BTreeStore<uint32_t, int32_t, - MinMaxAggregated, - std::less<uint32_t>, - BTreeDefaultTraits, - MinMaxAggrCalc>; +template class BTreeStore<uint32_t, uint32_t, NoAggregated, std::less<uint32_t>, BTreeDefaultTraits>; +template class BTreeStore<uint32_t, BTreeNoLeafData, NoAggregated, std::less<uint32_t>, BTreeDefaultTraits>; +template class BTreeStore<uint32_t, int32_t, MinMaxAggregated, std::less<uint32_t>, BTreeDefaultTraits, MinMaxAggrCalc>; } diff --git a/searchlib/src/vespa/searchlib/btree/btreestore.hpp b/searchlib/src/vespa/searchlib/btree/btreestore.hpp index f97a647287f..b4d82a9e31a 100644 --- a/searchlib/src/vespa/searchlib/btree/btreestore.hpp +++ b/searchlib/src/vespa/searchlib/btree/btreestore.hpp @@ -3,16 +3,12 @@ #pragma once #include "btreestore.h" -#include <vespa/searchlib/bitcompression/compression.h> #include "btreebuilder.h" #include "btreebuilder.hpp" #include <vespa/searchlib/datastore/datastore.hpp> +#include <vespa/searchlib/bitcompression/compression.h> -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT, typename AggrCalcT> @@ -958,8 +954,4 @@ getAggregated(const EntryRef ref) const return a; } -} // namespace btree - -} // namespace search - - +} diff --git a/searchlib/src/vespa/searchlib/btree/minmaxaggrcalc.h b/searchlib/src/vespa/searchlib/btree/minmaxaggrcalc.h index ef543905155..b33422ec3e3 100644 --- a/searchlib/src/vespa/searchlib/btree/minmaxaggrcalc.h +++ b/searchlib/src/vespa/searchlib/btree/minmaxaggrcalc.h @@ -2,10 +2,9 @@ #pragma once -namespace search -{ -namespace btree -{ +#include "minmaxaggregated.h" + +namespace search::btree { class MinMaxAggrCalc { @@ -48,7 +47,4 @@ public: } }; - -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/minmaxaggregated.h b/searchlib/src/vespa/searchlib/btree/minmaxaggregated.h index 65dd4839020..add570a6e6b 100644 --- a/searchlib/src/vespa/searchlib/btree/minmaxaggregated.h +++ b/searchlib/src/vespa/searchlib/btree/minmaxaggregated.h @@ -3,10 +3,9 @@ #pragma once #include <limits> -#include <stdint.h> +#include <cstdint> -namespace search { -namespace btree { +namespace search::btree { class MinMaxAggregated { @@ -103,7 +102,4 @@ public: } }; - -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/noaggrcalc.h b/searchlib/src/vespa/searchlib/btree/noaggrcalc.h index 2b3fafb6624..e77e8bc204a 100644 --- a/searchlib/src/vespa/searchlib/btree/noaggrcalc.h +++ b/searchlib/src/vespa/searchlib/btree/noaggrcalc.h @@ -2,10 +2,9 @@ #pragma once -namespace search -{ -namespace btree -{ +#include "noaggregated.h" + +namespace search::btree { class NoAggrCalc { @@ -92,7 +91,4 @@ public: } }; - -} // namespace search::btree -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/btree/noaggregated.h b/searchlib/src/vespa/searchlib/btree/noaggregated.h index 33533f18014..e16465f5e0a 100644 --- a/searchlib/src/vespa/searchlib/btree/noaggregated.h +++ b/searchlib/src/vespa/searchlib/btree/noaggregated.h @@ -2,10 +2,7 @@ #pragma once -namespace search -{ -namespace btree -{ +namespace search::btree { class NoAggregated { @@ -15,7 +12,4 @@ public: bool operator!=(const NoAggregated &) const { return false; } }; - -} // namespace search::btree -} // namespace search - +} |