diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-09-29 15:21:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-29 15:21:14 +0200 |
commit | dd0fe3dffb637fd03309847cc0f94a8f9dd5a796 (patch) | |
tree | dd6298d769fad9fce1c7732740e1648603b8b410 | |
parent | 210b35b7094bb09c287d27557bca005ce0926ace (diff) | |
parent | 7b34462940c2501e229e29f1f083edf297a2b885 (diff) |
Merge pull request #28728 from vespa-engine/toregge/reduce-code-duplication-between-fill-array-and-fill-bitvector
Reduce code duplication between fillArray and fillBitVector in
-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>(); } } |