diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-14 11:21:00 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-14 11:21:47 +0200 |
commit | f400647e7aa0696dc847f765872dc318f01de559 (patch) | |
tree | b843112addbd7a069927c62db76af2ecb10b890d /searchlib | |
parent | 251c18c61ee177fa9c59b35a0ae65e2ef7ff9f3d (diff) |
Code cleanup while considering options for hit estimation.
- Less includes
- std::make_unique
- alignment
- GC unused code.
Diffstat (limited to 'searchlib')
9 files changed, 197 insertions, 243 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp index 6abf0ac5f27..1908d22d7b9 100644 --- a/searchlib/src/vespa/searchlib/attribute/attributevector.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attributevector.cpp @@ -579,10 +579,10 @@ AttributeVector::SearchContext:: createIterator(fef::TermFieldMatchData *matchData, bool strict) { if (_plsc != NULL) { - SearchIterator::UP res = - _plsc->createPostingIterator(matchData, strict); - if (res.get() != NULL) + SearchIterator::UP res = _plsc->createPostingIterator(matchData, strict); + if (res) { return res; + } } return createFilterIterator(matchData, strict); } diff --git a/searchlib/src/vespa/searchlib/attribute/postingchange.cpp b/searchlib/src/vespa/searchlib/attribute/postingchange.cpp index c972e25a7cf..0b7430599b9 100644 --- a/searchlib/src/vespa/searchlib/attribute/postingchange.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postingchange.cpp @@ -4,6 +4,7 @@ #include "multivalue.h" #include "multi_value_mapping.h" #include "postinglistattribute.h" +#include <vespa/searchlib/common/growablebitvector.h> #include <vespa/vespalib/util/array.hpp> namespace search { diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h index 9665872f8de..cb3dd844041 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h @@ -6,13 +6,11 @@ #include "postinglisttraits.h" #include "postingstore.h" #include "ipostinglistsearchcontext.h" -#include "attributevector.h" +#include <vespa/searchcommon/attribute/search_context_params.h> +#include <vespa/searchcommon/common/range.h> #include <vespa/vespalib/util/regexp.h> -#include <cstdlib> -namespace search { - -namespace attribute { +namespace search::attribute { /** * Search context helper for posting list attributes, used to instantiate @@ -22,11 +20,11 @@ namespace attribute { class PostingListSearchContext : public IPostingListSearchContext { protected: - typedef EnumPostingTree Dictionary; - typedef Dictionary::ConstIterator DictionaryConstIterator; - typedef Dictionary::FrozenView FrozenDictionary; - typedef EnumStoreBase::Index EnumIndex; - + using Dictionary = EnumPostingTree; + using DictionaryConstIterator = Dictionary::ConstIterator; + using FrozenDictionary = Dictionary::FrozenView; + using EnumIndex = EnumStoreBase::Index; + const FrozenDictionary _frozenDictionary; DictionaryConstIterator _lowerDictItr; DictionaryConstIterator _upperDictItr; @@ -36,22 +34,17 @@ protected: uint64_t _numValues; // attr.getStatus().getNumValues(); bool _hasWeight; bool _useBitVector; - search::datastore::EntryRef _pidx; - search::datastore::EntryRef _frozenRoot; // Posting list in tree form + datastore::EntryRef _pidx; + datastore::EntryRef _frozenRoot; // Posting list in tree form float _FSTC; // Filtering Search Time Constant float _PLSTC; // Posting List Search Time Constant const EnumStoreBase &_esb; uint32_t _minBvDocFreq; const GrowableBitVector *_gbv; // bitvector if _useBitVector has been set - - PostingListSearchContext(const Dictionary &dictionary, - uint32_t docIdLimit, - uint64_t numValues, - bool hasWeight, - const EnumStoreBase &esb, - uint32_t minBvDocFreq, - bool useBitVector); + + PostingListSearchContext(const Dictionary &dictionary, uint32_t docIdLimit, uint64_t numValues, bool hasWeight, + const EnumStoreBase &esb, uint32_t minBvDocFreq, bool useBitVector); ~PostingListSearchContext(); @@ -96,13 +89,13 @@ template <class DataT> class PostingListSearchContextT : public PostingListSearchContext { protected: - typedef DataT DataType; - typedef PostingListTraits<DataType> Traits; - typedef typename Traits::PostingList PostingList; - typedef typename Traits::Posting Posting; - typedef std::vector<Posting> PostingVector; - typedef datastore::EntryRef EntryRef; - typedef typename PostingList::ConstIterator PostingConstIterator; + using DataType = DataT; + using Traits = PostingListTraits<DataType>; + using PostingList = typename Traits::PostingList; + using Posting = typename Traits::Posting; + using PostingVector = std::vector<Posting>; + using EntryRef = datastore::EntryRef; + using FrozenView = typename PostingList::BTreeType::FrozenView; const PostingList &_postingList; /* @@ -112,19 +105,14 @@ protected: std::unique_ptr<BitVector> _bitVector; bool _fetchPostingsDone; bool _arrayValid; - + static const long MIN_UNIQUE_VALUES_BEFORE_APPROXIMATION = 100; static const long MIN_UNIQUE_VALUES_TO_NUMDOCS_RATIO_BEFORE_APPROXIMATION = 20; static const long MIN_APPROXHITS_TO_NUMDOCS_RATIO_BEFORE_APPROXIMATION = 10; - PostingListSearchContextT(const Dictionary &dictionary, - uint32_t docIdLimit, - uint64_t numValues, - bool hasWeight, - const PostingList &postingList, - const EnumStoreBase &esb, - uint32_t minBvCocFreq, - bool useBitVector); + PostingListSearchContextT(const Dictionary &dictionary, uint32_t docIdLimit, uint64_t numValues, + bool hasWeight, const PostingList &postingList, const EnumStoreBase &esb, + uint32_t minBvCocFreq, bool useBitVector); ~PostingListSearchContextT(); void lookupSingle(); @@ -133,16 +121,14 @@ protected: void fillBitVector(); PostingVector & - merge(PostingVector &v, PostingVector &temp, - const std::vector<size_t> & startPos) __attribute__((noinline)); + merge(PostingVector &v, PostingVector &temp, const std::vector<size_t> & startPos) __attribute__((noinline)); void fetchPostings(bool strict) override; // this will be called instead of the fetchPostings function in some cases - void diversify(bool forward, size_t wanted_hits, - const IAttributeVector &diversity_attr, size_t max_per_group, - size_t cutoff_groups, bool cutoff_strict); + void diversify(bool forward, size_t wanted_hits, const IAttributeVector &diversity_attr, + size_t max_per_group, size_t cutoff_groups, bool cutoff_strict); - queryeval::SearchIterator::UP + std::unique_ptr<queryeval::SearchIterator> createPostingIterator(fef::TermFieldMatchData *matchData, bool strict) override; unsigned int singleHits() const; @@ -155,9 +141,9 @@ template <class DataT> class PostingListFoldedSearchContextT : public PostingListSearchContextT<DataT> { protected: - typedef PostingListSearchContextT<DataT> Parent; - typedef typename Parent::Dictionary Dictionary; - typedef typename Parent::PostingList PostingList; + using Parent = PostingListSearchContextT<DataT>; + using Dictionary = typename Parent::Dictionary; + using PostingList = typename Parent::PostingList; using Parent::_lowerDictItr; using Parent::_uniqueValues; using Parent::_postingList; @@ -165,14 +151,9 @@ protected: using Parent::countHits; using Parent::singleHits; - PostingListFoldedSearchContextT(const Dictionary &dictionary, - uint32_t docIdLimit, - uint64_t numValues, - bool hasWeight, - const PostingList &postingList, - const EnumStoreBase &esb, - uint32_t minBvCocFreq, - bool useBitVector); + PostingListFoldedSearchContextT(const Dictionary &dictionary, uint32_t docIdLimit, uint64_t numValues, + bool hasWeight, const PostingList &postingList, const EnumStoreBase &esb, + uint32_t minBvCocFreq, bool useBitVector); unsigned int approximateHits() const override; }; @@ -183,12 +164,12 @@ class PostingSearchContext: public BaseSC, public BaseSC2 { public: - typedef typename AttrT::EnumStore EnumStore; + using EnumStore = typename AttrT::EnumStore; using QueryTermSimpleUP = std::unique_ptr<QueryTermSimple>; protected: const AttrT &_toBeSearched; const EnumStore &_enumStore; - + PostingSearchContext(QueryTermSimpleUP qTerm, bool useBitVector, const AttrT &toBeSearched); ~PostingSearchContext(); }; @@ -198,14 +179,11 @@ class StringPostingSearchContext : public PostingSearchContext<BaseSC, PostingListFoldedSearchContextT<DataT>, AttrT> { private: - typedef PostingListTraits<DataT> AggregationTraits; - typedef typename AggregationTraits::PostingList PostingList; - typedef typename PostingList::Iterator PostingIterator; - typedef typename PostingList::ConstIterator PostingConstIterator; - typedef PostingSearchContext<BaseSC, PostingListFoldedSearchContextT<DataT>, AttrT> Parent; - typedef typename Parent::EnumStore EnumStore; - typedef typename EnumStore::FoldedComparatorType FoldedComparatorType; - typedef vespalib::Regexp Regexp; + using AggregationTraits = PostingListTraits<DataT>; + using PostingList = typename AggregationTraits::PostingList; + using Parent = PostingSearchContext<BaseSC, PostingListFoldedSearchContextT<DataT>, AttrT>; + using FoldedComparatorType = typename Parent::EnumStore::FoldedComparatorType; + using Regexp = vespalib::Regexp; using QueryTermSimpleUP = typename Parent::QueryTermSimpleUP; using Parent::_toBeSearched; using Parent::_enumStore; @@ -225,10 +203,7 @@ private: typedef PostingSearchContext<BaseSC, PostingListSearchContextT<DataT>, AttrT> Parent; typedef PostingListTraits<DataT> AggregationTraits; typedef typename AggregationTraits::PostingList PostingList; - typedef typename PostingList::Iterator PostingIterator; - typedef typename PostingList::ConstIterator PostingConstIterator; - typedef typename Parent::EnumStore EnumStore; - typedef typename EnumStore::ComparatorType ComparatorType; + typedef typename Parent::EnumStore::ComparatorType ComparatorType; typedef typename AttrT::T BaseType; using Params = attribute::SearchContextParams; using QueryTermSimpleUP = typename Parent::QueryTermSimpleUP; @@ -237,7 +212,7 @@ private: using Parent::_toBeSearched; using Parent::_enumStore; Params _params; - + void getIterators(bool shouldApplyRangeLimit); bool valid() const override { return this->isValid(); } @@ -269,8 +244,8 @@ public: NumericPostingSearchContext(QueryTermSimpleUP qTerm, const Params & params, const AttrT &toBeSearched); const Params ¶ms() const { return _params; } }; - - + + template <typename BaseSC, typename BaseSC2, typename AttrT> PostingSearchContext<BaseSC, BaseSC2, AttrT>:: PostingSearchContext(QueryTermSimpleUP qTerm, bool useBitVector, const AttrT &toBeSearched) @@ -305,7 +280,7 @@ StringPostingSearchContext(QueryTermSimpleUP qTerm, bool useBitVector, const Att // after benchmarking prefix search performance on single, array, and weighted set fast-search string attributes // with 1M values the following constant has been derived: this->_PLSTC = 0.000000; - + if (this->valid()) { if (this->isPrefix()) { FoldedComparatorType comp(_enumStore, this->queryTerm().getTerm(), true); @@ -386,7 +361,4 @@ extern template class PostingListSearchContextT<int32_t>; extern template class PostingListFoldedSearchContextT<btree::BTreeNoLeafData>; extern template class PostingListFoldedSearchContextT<int32_t>; -} // namespace attribute - -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp index 270ae161f4c..918a8a0f0b3 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp @@ -5,28 +5,23 @@ #include "dociditerator.h" #include "attributeiterators.h" #include "diversity.h" +#include "postingstore.hpp" #include <vespa/searchlib/queryeval/emptysearch.h> #include <vespa/searchlib/common/bitvectoriterator.h> +#include <vespa/searchlib/common/growablebitvector.h> -namespace search { -using queryeval::EmptySearch; -using queryeval::SearchIterator; +using search::queryeval::EmptySearch; +using search::queryeval::SearchIterator; -namespace attribute { +namespace search::attribute { template <typename DataT> PostingListSearchContextT<DataT>:: -PostingListSearchContextT(const Dictionary &dictionary, - uint32_t docIdLimit, - uint64_t numValues, - bool hasWeight, - const PostingList &postingList, - const EnumStoreBase &esb, - uint32_t minBvDocFreq, - bool useBitVector) - : PostingListSearchContext(dictionary, docIdLimit, numValues, hasWeight, - esb, minBvDocFreq, useBitVector), +PostingListSearchContextT(const Dictionary &dictionary, uint32_t docIdLimit, uint64_t numValues, bool hasWeight, + const PostingList &postingList, const EnumStoreBase &esb, + uint32_t minBvDocFreq, bool useBitVector) + : PostingListSearchContext(dictionary, docIdLimit, numValues, hasWeight, esb, minBvDocFreq, useBitVector), _postingList(postingList), _array(), _bitVector(), @@ -56,9 +51,7 @@ PostingListSearchContextT<DataT>::lookupSingle() } else { _pidx = bve->_tree; if (_pidx.valid()) { - typename PostingList::BTreeType::FrozenView - frozenView(_postingList.getTreeEntry(_pidx)-> - getFrozenView(_postingList.getAllocator())); + auto frozenView = _postingList.getTreeEntry(_pidx)->getFrozenView(_postingList.getAllocator()); _frozenRoot = frozenView.getRoot(); if (!_frozenRoot.valid()) { _pidx = datastore::EntryRef(); @@ -68,9 +61,7 @@ PostingListSearchContextT<DataT>::lookupSingle() } } } else { - typename PostingList::BTreeType::FrozenView - frozenView(_postingList.getTreeEntry(_pidx)-> - getFrozenView(_postingList.getAllocator())); + auto frozenView = _postingList.getTreeEntry(_pidx)->getFrozenView(_postingList.getAllocator()); _frozenRoot = frozenView.getRoot(); if (!_frozenRoot.valid()) { _pidx = datastore::EntryRef(); @@ -106,8 +97,8 @@ PostingListSearchContextT<DataT>::fillArray(size_t numDocs) for (auto it(_lowerDictItr); it != _upperDictItr; ++it) { if (useThis(it)) { _postingList.foreach_frozen(it.getData(), - [&](uint32_t key, const DataT &data) - { _array.push_back(Posting(key, data)); + [&](uint32_t key, const DataT &data) { + _array.push_back(Posting(key, data)); }); startPos.push_back(_array.size()); } @@ -130,8 +121,8 @@ PostingListSearchContextT<DataT>::fillBitVector() for (auto it(_lowerDictItr); it != _upperDictItr; ++it) { if (useThis(it)) { _postingList.foreach_frozen_key(it.getData(), - [&](uint32_t key) - { if (key < limit) { + [&](uint32_t key) { + if (key < limit) { bv.setBit(key); } }); @@ -193,9 +184,8 @@ PostingListSearchContextT<DataT>::fetchPostings(bool strict) template <typename DataT> void -PostingListSearchContextT<DataT>::diversify(bool forward, size_t wanted_hits, - const IAttributeVector &diversity_attr, size_t max_per_group, - size_t cutoff_groups, bool cutoff_strict) +PostingListSearchContextT<DataT>::diversify(bool forward, size_t wanted_hits, const IAttributeVector &diversity_attr, + size_t max_per_group, size_t cutoff_groups, bool cutoff_strict) { assert(!_fetchPostingsDone); _fetchPostingsDone = true; @@ -203,9 +193,8 @@ PostingListSearchContextT<DataT>::diversify(bool forward, size_t wanted_hits, _array.reserve(wanted_hits); std::vector<size_t> fragments; fragments.push_back(0); - diversity::diversify(forward, _lowerDictItr, _upperDictItr, _postingList, wanted_hits, - diversity_attr, max_per_group, cutoff_groups, cutoff_strict, - _array, fragments); + diversity::diversify(forward, _lowerDictItr, _upperDictItr, _postingList, wanted_hits, diversity_attr, + max_per_group, cutoff_groups, cutoff_strict, _array, fragments); if (fragments.size() > 2) { PostingVector temp(_array.size()); _array.swap(merge(_array, temp, fragments)); @@ -226,12 +215,14 @@ createPostingIterator(fef::TermFieldMatchData *matchData, bool strict) if (_arrayValid || (_bitVector.get() != nullptr)) { // synthetic results are available if (!_array.empty()) { assert(_arrayValid); - typedef DocIdIterator<Posting> DocIt; + using DocIt = DocIdIterator<Posting>; DocIt postings; postings.set(&_array[0], &_array[_array.size()]); - return (_postingList._isFilter) - ? SearchIterator::UP(new FilterAttributePostingListIteratorT<DocIt>(matchData, postings)) - : SearchIterator::UP(new AttributePostingListIteratorT<DocIt>(_hasWeight, matchData, postings)); + if (_postingList._isFilter) { + return std::make_unique<FilterAttributePostingListIteratorT<DocIt>>(matchData, postings); + } else { + return std::make_unique<AttributePostingListIteratorT<DocIt>>(_hasWeight, matchData, postings); + } } if (_arrayValid) { return SearchIterator::UP(new EmptySearch()); @@ -251,19 +242,24 @@ createPostingIterator(fef::TermFieldMatchData *matchData, bool strict) if (!_frozenRoot.valid()) { uint32_t clusterSize = _postingList.getClusterSize(_pidx); assert(clusterSize != 0); - typedef DocIdMinMaxIterator<Posting> DocIt; + using DocIt = DocIdMinMaxIterator<Posting>; DocIt postings; const Posting *array = postingList.getKeyDataEntry(_pidx, clusterSize); postings.set(array, array + clusterSize); - return (postingList._isFilter) - ? SearchIterator::UP(new FilterAttributePostingListIteratorT<DocIt>(matchData, postings)) - : SearchIterator::UP(new AttributePostingListIteratorT<DocIt>(_hasWeight, matchData, postings)); + if (postingList._isFilter) { + return std::make_unique<FilterAttributePostingListIteratorT<DocIt>>(matchData, postings); + } else { + return std::make_unique<AttributePostingListIteratorT<DocIt>>(_hasWeight, matchData, postings); + } } typename PostingList::BTreeType::FrozenView frozen(_frozenRoot, postingList.getAllocator()); - return (_postingList._isFilter) - ? SearchIterator::UP(new FilterAttributePostingListIteratorT<PostingConstIterator> (matchData, frozen.getRoot(), frozen.getAllocator())) - : SearchIterator::UP(new AttributePostingListIteratorT<PostingConstIterator> (_hasWeight, matchData, frozen.getRoot(), frozen.getAllocator())); + using DocIt = typename PostingList::ConstIterator; + if (_postingList._isFilter) { + return std::make_unique<FilterAttributePostingListIteratorT<DocIt>>(matchData, frozen.getRoot(), frozen.getAllocator()); + } else { + return std::make_unique<AttributePostingListIteratorT<DocIt>> (_hasWeight, matchData, frozen.getRoot(), frozen.getAllocator()); + } } // returning nullptr will trigger fallback to filter iterator return SearchIterator::UP(); @@ -346,16 +342,10 @@ PostingListSearchContextT<DataT>::applyRangeLimit(int rangeLimit) template <typename DataT> PostingListFoldedSearchContextT<DataT>:: -PostingListFoldedSearchContextT(const Dictionary &dictionary, - uint32_t docIdLimit, - uint64_t numValues, - bool hasWeight, - const PostingList &postingList, - const EnumStoreBase &esb, - uint32_t minBvDocFreq, - bool useBitVector) - : Parent(dictionary, docIdLimit, numValues, hasWeight, postingList, - esb, minBvDocFreq, useBitVector) +PostingListFoldedSearchContextT(const Dictionary &dictionary, uint32_t docIdLimit, uint64_t numValues, + bool hasWeight, const PostingList &postingList, const EnumStoreBase &esb, + uint32_t minBvDocFreq, bool useBitVector) + : Parent(dictionary, docIdLimit, numValues, hasWeight, postingList, esb, minBvDocFreq, useBitVector) { } @@ -379,7 +369,4 @@ PostingListFoldedSearchContextT<DataT>::approximateHits() const return numHits; } -} // namespace attribute - -} // namespace search - +} diff --git a/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h b/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h index c2504f779a1..d619751d451 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h +++ b/searchlib/src/vespa/searchlib/attribute/postinglisttraits.h @@ -4,11 +4,9 @@ #include <vespa/searchlib/btree/btreestore.h> -namespace search -{ +namespace search { -namespace attribute -{ +namespace attribute { template <typename DataT> class PostingListTraits; template <typename DataT> class PostingStore; diff --git a/searchlib/src/vespa/searchlib/attribute/postingstore.cpp b/searchlib/src/vespa/searchlib/attribute/postingstore.cpp index a21884bca4a..e1b0cf24305 100644 --- a/searchlib/src/vespa/searchlib/attribute/postingstore.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postingstore.cpp @@ -3,12 +3,11 @@ #include "postingstore.h" #include <vespa/searchlib/datastore/datastore.hpp> #include <vespa/searchlib/btree/btreeiterator.hpp> +#include <vespa/searchlib/common/growablebitvector.h> #include <vespa/searchcommon/attribute/config.h> #include <vespa/searchcommon/attribute/status.h> -namespace search { - -namespace attribute { +namespace search::attribute { using btree::BTreeNoLeafData; @@ -635,6 +634,4 @@ template class PostingStore<BTreeNoLeafData>; template class PostingStore<int32_t>; -} // namespace btree - -} // namespace search +} diff --git a/searchlib/src/vespa/searchlib/attribute/postingstore.h b/searchlib/src/vespa/searchlib/attribute/postingstore.h index 9aae723db73..9c34344451a 100644 --- a/searchlib/src/vespa/searchlib/attribute/postingstore.h +++ b/searchlib/src/vespa/searchlib/attribute/postingstore.h @@ -5,12 +5,13 @@ #include "postinglisttraits.h" #include "enumstorebase.h" #include <set> -#include <vespa/searchlib/common/bitvector.h> -#include <vespa/searchlib/common/growablebitvector.h> namespace search { + class BitVector; + class GrowableBitVector; +} -namespace attribute { +namespace search::attribute { class Status; class Config; @@ -43,9 +44,9 @@ public: uint32_t _maxBvDocFreq; // Greater than or equal to this ==> create bv protected: std::set<uint32_t> _bvs; // Current bitvectors - EnumPostingTree &_dict; - Status &_status; - uint64_t _bvExtraBytes; + EnumPostingTree &_dict; + Status &_status; + uint64_t _bvExtraBytes; static constexpr uint32_t BUFFERTYPE_BITVECTOR = 9u; @@ -197,90 +198,4 @@ PostingStore<int32_t>::bitVectorWeight() return 1; } -template <typename DataT> -template <typename FunctionType> -void -PostingStore<DataT>::foreach_frozen_key(EntryRef ref, FunctionType func) const -{ - if (!ref.valid()) - return; - RefType iRef(ref); - uint32_t typeId = getTypeId(iRef); - uint32_t clusterSize = getClusterSize(typeId); - if (clusterSize == 0) { - if (isBitVector(typeId)) { - const BitVectorEntry *bve = getBitVectorEntry(iRef); - EntryRef ref2(bve->_tree); - RefType iRef2(ref2); - if (iRef2.valid()) { - assert(isBTree(iRef2)); - const BTreeType *tree = getTreeEntry(iRef2); - _allocator.getNodeStore().foreach_key(tree->getFrozenRoot(), func); - } else { - const BitVector *bv = bve->_bv.get(); - uint32_t docIdLimit = bv->size(); - uint32_t docId = bv->getFirstTrueBit(1); - while (docId < docIdLimit) { - func(docId); - docId = bv->getNextTrueBit(docId + 1); - } - } - } else { - assert(isBTree(typeId)); - const BTreeType *tree = getTreeEntry(iRef); - _allocator.getNodeStore().foreach_key(tree->getFrozenRoot(), func); - } - } else { - const KeyDataType *p = getKeyDataEntry(iRef, clusterSize); - const KeyDataType *pe = p + clusterSize; - for (; p != pe; ++p) { - func(p->_key); - } - } -} - - -template <typename DataT> -template <typename FunctionType> -void -PostingStore<DataT>::foreach_frozen(EntryRef ref, FunctionType func) const -{ - if (!ref.valid()) - return; - RefType iRef(ref); - uint32_t typeId = getTypeId(iRef); - uint32_t clusterSize = getClusterSize(typeId); - if (clusterSize == 0) { - if (isBitVector(typeId)) { - const BitVectorEntry *bve = getBitVectorEntry(iRef); - EntryRef ref2(bve->_tree); - RefType iRef2(ref2); - if (iRef2.valid()) { - assert(isBTree(iRef2)); - const BTreeType *tree = getTreeEntry(iRef2); - _allocator.getNodeStore().foreach(tree->getFrozenRoot(), func); - } else { - const BitVector *bv = bve->_bv.get(); - uint32_t docIdLimit = bv->size(); - uint32_t docId = bv->getFirstTrueBit(1); - while (docId < docIdLimit) { - func(docId, bitVectorWeight()); - docId = bv->getNextTrueBit(docId + 1); - } - } - } else { - const BTreeType *tree = getTreeEntry(iRef); - _allocator.getNodeStore().foreach(tree->getFrozenRoot(), func); - } - } else { - const KeyDataType *p = getKeyDataEntry(iRef, clusterSize); - const KeyDataType *pe = p + clusterSize; - for (; p != pe; ++p) { - func(p->_key, p->getData()); - } - } } - -} // namespace attribute - -} // namespace search diff --git a/searchlib/src/vespa/searchlib/attribute/postingstore.hpp b/searchlib/src/vespa/searchlib/attribute/postingstore.hpp new file mode 100644 index 00000000000..6680fc86f71 --- /dev/null +++ b/searchlib/src/vespa/searchlib/attribute/postingstore.hpp @@ -0,0 +1,90 @@ +#pragma once + +#include "postingstore.h" +#include <vespa/searchlib/common/growablebitvector.h> + +namespace search::attribute { + +template<typename DataT> +template<typename FunctionType> +void +PostingStore<DataT>::foreach_frozen_key(EntryRef ref, FunctionType func) const { + if (!ref.valid()) + return; + RefType iRef(ref); + uint32_t typeId = getTypeId(iRef); + uint32_t clusterSize = getClusterSize(typeId); + if (clusterSize == 0) { + if (isBitVector(typeId)) { + const BitVectorEntry *bve = getBitVectorEntry(iRef); + EntryRef ref2(bve->_tree); + RefType iRef2(ref2); + if (iRef2.valid()) { + assert(isBTree(iRef2)); + const BTreeType *tree = getTreeEntry(iRef2); + _allocator.getNodeStore().foreach_key(tree->getFrozenRoot(), func); + } else { + const BitVector *bv = bve->_bv.get(); + uint32_t docIdLimit = bv->size(); + uint32_t docId = bv->getFirstTrueBit(1); + while (docId < docIdLimit) { + func(docId); + docId = bv->getNextTrueBit(docId + 1); + } + } + } else { + assert(isBTree(typeId)); + const BTreeType *tree = getTreeEntry(iRef); + _allocator.getNodeStore().foreach_key(tree->getFrozenRoot(), func); + } + } else { + const KeyDataType *p = getKeyDataEntry(iRef, clusterSize); + const KeyDataType *pe = p + clusterSize; + for (; p != pe; ++p) { + func(p->_key); + } + } +} + + +template<typename DataT> +template<typename FunctionType> +void +PostingStore<DataT>::foreach_frozen(EntryRef ref, FunctionType func) const { + if (!ref.valid()) + return; + RefType iRef(ref); + uint32_t typeId = getTypeId(iRef); + uint32_t clusterSize = getClusterSize(typeId); + if (clusterSize == 0) { + if (isBitVector(typeId)) { + const BitVectorEntry *bve = getBitVectorEntry(iRef); + EntryRef ref2(bve->_tree); + RefType iRef2(ref2); + if (iRef2.valid()) { + assert(isBTree(iRef2)); + const BTreeType *tree = getTreeEntry(iRef2); + _allocator.getNodeStore().foreach(tree->getFrozenRoot(), func); + } else { + const BitVector *bv = bve->_bv.get(); + uint32_t docIdLimit = bv->size(); + uint32_t docId = bv->getFirstTrueBit(1); + while (docId < docIdLimit) { + func(docId, bitVectorWeight()); + docId = bv->getNextTrueBit(docId + 1); + } + } + } else { + const BTreeType *tree = getTreeEntry(iRef); + _allocator.getNodeStore().foreach(tree->getFrozenRoot(), func); + } + } else { + const KeyDataType *p = getKeyDataEntry(iRef, clusterSize); + const KeyDataType *pe = p + clusterSize; + for (; p != pe; ++p) { + func(p->_key, p->getData()); + } + } +} + +} diff --git a/searchlib/src/vespa/searchlib/btree/btreestore.h b/searchlib/src/vespa/searchlib/btree/btreestore.h index e8153f94363..c22d2dd3f55 100644 --- a/searchlib/src/vespa/searchlib/btree/btreestore.h +++ b/searchlib/src/vespa/searchlib/btree/btreestore.h @@ -10,11 +10,7 @@ #include <vespa/searchlib/datastore/datastore.h> #include <vespa/searchlib/datastore/handle.h> -namespace search -{ - -namespace btree -{ +namespace search::btree { template <typename KeyT, typename DataT, @@ -508,8 +504,6 @@ extern template class BTreeStore<uint32_t, int32_t, BTreeDefaultTraits, MinMaxAggrCalc>; -} // namespace btree - -} // namespace search +} |