diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-09-29 13:54:37 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-09-29 13:54:37 +0200 |
commit | 7b34462940c2501e229e29f1f083edf297a2b885 (patch) | |
tree | 1434bc6b877ea9ff5abd49d9292ca821ee1e330f /searchlib | |
parent | b6e402c67d9a6c9f63355e7e553de2b89d1b06a9 (diff) |
Reduce code duplication between fillArray and fillBitVector in
PostingListFoldedSearchContextT.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h | 4 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp | 54 |
2 files changed, 35 insertions, 23 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h index 9a4dbdd9c61..07f4d1bf204 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h @@ -182,6 +182,10 @@ protected: bool fallback_to_approx_num_hits() const override; size_t countHits() const override; + template <bool fill_array> + void fill_array_or_bitvector_helper(EntryRef pidx); + template <bool fill_array> + void fill_array_or_bitvector(); void fillArray() override; void fillBitVector() override; }; diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp index c479bbfcd06..bae6be20b8b 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.hpp @@ -306,48 +306,56 @@ PostingListFoldedSearchContextT<DataT>::countHits() const ++it; } } - if (!overflow) { - _resume_scan_itr = _upperDictItr; - } _counted_hits = sum; return sum; } template <typename DataT> +template <bool fill_array> void -PostingListFoldedSearchContextT<DataT>::fillArray() +PostingListFoldedSearchContextT<DataT>::fill_array_or_bitvector_helper(EntryRef pidx) { - for (auto pidx : _posting_indexes) { + if constexpr (fill_array) { _merger.addToArray(PostingListTraverser<PostingList>(_postingList, pidx)); + } else { + _merger.addToBitVector(PostingListTraverser<PostingList>(_postingList, pidx)); } - for (auto it(_resume_scan_itr); it != _upperDictItr;) { - if (use_dictionary_entry(it)) { - auto pidx = it.getData().load_acquire(); - if (pidx.valid()) { - _merger.addToArray(PostingListTraverser<PostingList>(_postingList, pidx)); - } - ++it; - } - } - _merger.merge(); } template <typename DataT> +template <bool fill_array> void -PostingListFoldedSearchContextT<DataT>::fillBitVector() +PostingListFoldedSearchContextT<DataT>::fill_array_or_bitvector() { for (auto pidx : _posting_indexes) { - _merger.addToBitVector(PostingListTraverser<PostingList>(_postingList, pidx)); + fill_array_or_bitvector_helper<fill_array>(pidx); } - for (auto it(_resume_scan_itr); it != _upperDictItr;) { - if (use_dictionary_entry(it)) { - auto pidx = it.getData().load_acquire(); - if (pidx.valid()) { - _merger.addToBitVector(PostingListTraverser<PostingList>(_postingList, pidx)); + if (_resume_scan_itr.valid()) { + for (auto it(_resume_scan_itr); it != _upperDictItr;) { + if (use_dictionary_entry(it)) { + auto pidx = it.getData().load_acquire(); + if (pidx.valid()) { + fill_array_or_bitvector_helper<fill_array>(pidx); + } + ++it; } - ++it; } } + _merger.merge(); +} + +template <typename DataT> +void +PostingListFoldedSearchContextT<DataT>::fillArray() +{ + fill_array_or_bitvector<true>(); +} + +template <typename DataT> +void +PostingListFoldedSearchContextT<DataT>::fillBitVector() +{ + fill_array_or_bitvector<false>(); } } |