diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-04-26 01:01:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-26 01:01:09 +0200 |
commit | 9754bda577ddda8454743e20e4842263875ec6a7 (patch) | |
tree | 3e4a3d59302f09ccaea51d7bb800408d48eb40ba | |
parent | a7c1a2ad35d805815d7845b74e4efd4bbcf4cf7a (diff) | |
parent | bec1ec03ae0dbb1a27c408d8484e9a959753b510 (diff) |
Merge branch 'master' into balder/add-noexcept
13 files changed, 209 insertions, 272 deletions
diff --git a/flags/src/main/java/com/yahoo/vespa/flags/Flags.java b/flags/src/main/java/com/yahoo/vespa/flags/Flags.java index ec98a1070e1..a3fe010c65b 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/Flags.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/Flags.java @@ -84,6 +84,12 @@ public class Flags { "Takes effect at redeployment", INSTANCE_ID); + public static final UnboundBooleanFlag NEW_RESOURCES_FORMULA = defineFeatureFlag( + "new-resources-formula", true, + List.of("hakonhall"), "2024-04-25", "2024-05-25", + "Use an easier to understand formula for calculating the memory and disk resources", + "Takes effect on next deployment of an applications."); + public static final UnboundBooleanFlag FIX_CONFIG_SERVER_HEAP = defineFeatureFlag( "fix-config-server-heap", false, List.of("hakonhall"), "2024-04-23", "2024-05-23", diff --git a/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.cpp b/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.cpp index 93bc4735916..3bd1682c470 100644 --- a/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.cpp +++ b/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.cpp @@ -10,20 +10,13 @@ template <typename IteratorType, typename RefType> PostingIteratorPack<IteratorType, RefType>::~PostingIteratorPack() = default; template <typename IteratorType, typename RefType> -PostingIteratorPack<IteratorType, RefType>::PostingIteratorPack(std::vector<IteratorType> &&children) +PostingIteratorPack<IteratorType, RefType>::PostingIteratorPack(std::vector<IteratorType> &&children) noexcept : _children(std::move(children)) { assert(_children.size() <= std::numeric_limits<ref_t>::max()); } template <typename IteratorType, typename RefType> -bool -PostingIteratorPack<IteratorType, RefType>::can_handle_iterators(size_t num_iterators) -{ - return num_iterators <= std::numeric_limits<ref_t>::max(); -} - -template <typename IteratorType, typename RefType> std::unique_ptr<BitVector> PostingIteratorPack<IteratorType, RefType>::get_hits(uint32_t begin_id, uint32_t end_id) { BitVector::UP result(BitVector::create(begin_id, end_id)); @@ -48,14 +41,14 @@ PostingIteratorPack<IteratorType, RefType>::or_hits_into(BitVector &result, uint template <> int32_t -PostingIteratorPack<DocidIterator, uint16_t>::get_weight(ref_t, uint32_t) +PostingIteratorPack<DocidIterator, uint16_t>::get_weight(ref_t, uint32_t) noexcept { return 1; } template <> int32_t -PostingIteratorPack<DocidIterator, uint32_t>::get_weight(ref_t, uint32_t) +PostingIteratorPack<DocidIterator, uint32_t>::get_weight(ref_t, uint32_t) noexcept { return 1; } diff --git a/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.h b/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.h index 7c6b85dd3ec..ce0163dc293 100644 --- a/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.h +++ b/searchlib/src/vespa/searchlib/attribute/posting_iterator_pack.h @@ -23,16 +23,18 @@ public: PostingIteratorPack(PostingIteratorPack &&rhs) noexcept = default; PostingIteratorPack &operator=(PostingIteratorPack &&rhs) noexcept = default; - explicit PostingIteratorPack(std::vector<IteratorType> &&children); + explicit PostingIteratorPack(std::vector<IteratorType> &&children) noexcept; ~PostingIteratorPack(); - static bool can_handle_iterators(size_t num_iterators); + constexpr static bool can_handle_iterators(size_t num_iterators) noexcept { + return num_iterators <= std::numeric_limits<ref_t>::max(); + } - uint32_t get_docid(ref_t ref) const { + uint32_t get_docid(ref_t ref) const noexcept { return _children[ref].valid() ? _children[ref].getKey() : endDocId; } - uint32_t seek(ref_t ref, uint32_t docid) { + uint32_t seek(ref_t ref, uint32_t docid) noexcept { _children[ref].linearSeek(docid); if (__builtin_expect(_children[ref].valid(), true)) { return _children[ref].getKey(); @@ -40,7 +42,7 @@ public: return endDocId; } - int32_t get_weight(ref_t ref, uint32_t) { + int32_t get_weight(ref_t ref, uint32_t) noexcept { return _children[ref].getData(); } @@ -48,14 +50,14 @@ public: void or_hits_into(BitVector &result, uint32_t begin_id); ref_t size() const noexcept { return _children.size(); } - void initRange(uint32_t begin, uint32_t end) { + void initRange(uint32_t begin, uint32_t end) noexcept { (void) end; for (auto &child: _children) { child.lower_bound(begin); } } private: - uint32_t next(ref_t ref) { + uint32_t next(ref_t ref) noexcept { ++_children[ref]; return get_docid(ref); } diff --git a/searchlib/src/vespa/searchlib/grouping/collect.cpp b/searchlib/src/vespa/searchlib/grouping/collect.cpp index d0a9a38bf7d..464362602f2 100644 --- a/searchlib/src/vespa/searchlib/grouping/collect.cpp +++ b/searchlib/src/vespa/searchlib/grouping/collect.cpp @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "collect.h" -#include <vespa/vespalib/util/array.hpp> #include <cassert> using namespace search::expression; @@ -48,8 +47,7 @@ Collect::~Collect() assert((_aggrBacking.size() % _aggregatorSize) == 0); for (size_t i(0), m(_aggrBacking.size()/_aggregatorSize); i < m; i++) { uint8_t * base(&_aggrBacking[ i * _aggregatorSize]); - for (size_t j(0), k(_aggregator.size()); j < k; j++) { - ResultAccessor & r = _aggregator[j]; + for (auto & r : _aggregator) { r.destroy(base); } } @@ -74,8 +72,8 @@ void Collect::collect(GroupRef gr, uint32_t docId, double rank) { uint8_t * base(&_aggrBacking[getAggrBase(gr)]); - for (size_t i(0), m(_aggregator.size()); i < m; i++) { - _aggregator[i].aggregate(base, docId, rank); + for (auto & i : _aggregator) { + i.aggregate(base, docId, rank); } } @@ -86,8 +84,7 @@ Collect::createCollectors(GroupRef gr) if (offset == _aggrBacking.size()) { _aggrBacking.resize(getAggrBase(GroupRef(gr.getRef() + 1))); uint8_t * base(&_aggrBacking[offset]); - for (size_t i(0), m(_aggregator.size()); i < m; i++) { - ResultAccessor & r = _aggregator[i]; + for (auto & r : _aggregator) { r.create(base); } } diff --git a/searchlib/src/vespa/searchlib/grouping/collect.h b/searchlib/src/vespa/searchlib/grouping/collect.h index 3566d21f821..932cf559156 100644 --- a/searchlib/src/vespa/searchlib/grouping/collect.h +++ b/searchlib/src/vespa/searchlib/grouping/collect.h @@ -13,7 +13,7 @@ public: Collect(const Collect &) = delete; Collect & operator = (const Collect &) = delete; protected: - Collect(const aggregation::Group & protoType); + explicit Collect(const aggregation::Group & protoType); ~Collect(); void preFill(GroupRef gr, const aggregation::Group & r); void createCollectors(GroupRef gr); @@ -55,9 +55,9 @@ private: */ class ResultAccessor { public: - ResultAccessor() : _bluePrint(NULL), _aggregator(NULL), _offset(0) { } + ResultAccessor() noexcept : _bluePrint(nullptr), _aggregator(nullptr), _offset(0) { } ResultAccessor(const aggregation::AggregationResult & aggregator, size_t offset); - void setResult(const expression::ResultNode & result, uint8_t * base) { + void setResult(const expression::ResultNode & result, uint8_t * base) const { result.encode(base+_offset); } const expression::ResultNode & getResult(expression::ResultNode & result, const uint8_t * base) const { @@ -86,8 +86,8 @@ private: mutable vespalib::IdentifiablePtr<aggregation::AggregationResult> _aggregator; uint32_t _offset; }; - using AggregatorBacking = vespalib::Array<uint8_t>; - using ResultAccessorList = vespalib::Array<ResultAccessor>; + using AggregatorBacking = std::vector<uint8_t>; + using ResultAccessorList = std::vector<ResultAccessor>; class SortInfo { public: SortInfo() noexcept : _index(0), _sign(1) { } @@ -98,10 +98,10 @@ private: uint8_t _index; // Which index in the aggragators should be used for sorting this level. int8_t _sign; // And which way. positive number -> ascending, negative number descending. }; - size_t _aggregatorSize; // This is the bytesize required to store the aggrgate values per bucket. - ResultAccessorList _aggregator; // These are the accessors to use when accessing the results. - AggregatorBacking _aggrBacking; // This is the storage for the accessors. - std::vector<SortInfo> _sortInfo; // Generated cheap sortInfo, to avoid accessing more complicated data. + size_t _aggregatorSize; // This is the bytesize required to store the aggrgate values per bucket. + ResultAccessorList _aggregator; // These are the accessors to use when accessing the results. + AggregatorBacking _aggrBacking; // This is the storage for the accessors. + std::vector<SortInfo> _sortInfo; // Generated cheap sortInfo, to avoid accessing more complicated data. }; } diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_search.cpp b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_search.cpp index f3028f5159a..9e887b9d0f7 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_search.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/wand/parallel_weak_and_search.cpp @@ -14,7 +14,6 @@ using vespalib::make_string; namespace search::queryeval { using MatchParams = ParallelWeakAndSearch::MatchParams; -using RankParams = ParallelWeakAndSearch::RankParams; namespace wand { @@ -22,7 +21,7 @@ namespace { bool should_monitor_wand() { return LOG_WOULD_LOG(spam); } } template <typename VectorizedTerms, typename FutureHeap, typename PastHeap, bool IS_STRICT> -class ParallelWeakAndSearchImpl : public ParallelWeakAndSearch +class ParallelWeakAndSearchImpl final : public ParallelWeakAndSearch { private: fef::TermFieldMatchData &_tfmd; @@ -120,8 +119,7 @@ insertMonitoringSearchIterator(const wand::Terms &terms) for (size_t i = 0; i < terms.size(); ++i) { wand::Term &t = retval[i]; t.search = new MonitoringSearchIterator - (make_string("w%d:e%u:m%" PRId64 "", - t.weight, t.estHits, DotProductScorer::calculateMaxScore(t)), + (make_string("w%d:e%u:m%" PRId64 "", t.weight, t.estHits, DotProductScorer::calculateMaxScore(t)), SearchIterator::UP(t.search), true); } return retval; @@ -167,11 +165,9 @@ ParallelWeakAndSearch::createArrayWand(const Terms &terms, RankParams &&rankParams, bool strict) { - if (strict) { - return wand::createWand<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, true>(terms, matchParams, std::move(rankParams)); - } else { - return wand::createWand<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, false>(terms, matchParams, std::move(rankParams)); - } + return strict + ? wand::createWand<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, true>(terms, matchParams, std::move(rankParams)) + : wand::createWand<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, false>(terms, matchParams, std::move(rankParams)); } SearchIterator::UP @@ -180,11 +176,9 @@ ParallelWeakAndSearch::createHeapWand(const Terms &terms, RankParams &&rankParams, bool strict) { - if (strict) { - return wand::createWand<vespalib::LeftHeap, vespalib::RightHeap, true>(terms, matchParams, std::move(rankParams)); - } else { - return wand::createWand<vespalib::LeftHeap, vespalib::RightHeap, false>(terms, matchParams, std::move(rankParams)); - } + return strict + ? wand::createWand<vespalib::LeftHeap, vespalib::RightHeap, true>(terms, matchParams, std::move(rankParams)) + : wand::createWand<vespalib::LeftHeap, vespalib::RightHeap, false>(terms, matchParams, std::move(rankParams)); } SearchIterator::UP @@ -193,11 +187,9 @@ ParallelWeakAndSearch::create(const Terms &terms, RankParams &&rankParams, bool strict) { - if (terms.size() < 128) { - return createArrayWand(terms, matchParams, std::move(rankParams), strict); - } else { - return createHeapWand(terms, matchParams, std::move(rankParams), strict); - } + return (terms.size() < 128) + ? createArrayWand(terms, matchParams, std::move(rankParams), strict) + : createHeapWand(terms, matchParams, std::move(rankParams), strict); } //----------------------------------------------------------------------------- @@ -206,9 +198,11 @@ namespace { template <typename VectorizedTerms, typename FutureHeap, typename PastHeap> SearchIterator::UP create_helper(search::fef::TermFieldMatchData &tfmd, VectorizedTerms &&terms, const MatchParams ¶ms, bool strict) { - return (strict) - ? SearchIterator::UP(new wand::ParallelWeakAndSearchImpl<VectorizedTerms, FutureHeap, PastHeap, true>(tfmd, std::move(terms), params)) - : SearchIterator::UP( new wand::ParallelWeakAndSearchImpl<VectorizedTerms, FutureHeap, PastHeap, false>(tfmd, std::move(terms), params)); + if (strict) { + return std::make_unique<wand::ParallelWeakAndSearchImpl<VectorizedTerms, FutureHeap, PastHeap, true>>(tfmd, std::move(terms), params); + } else { + return std::make_unique<wand::ParallelWeakAndSearchImpl<VectorizedTerms, FutureHeap, PastHeap, false>>(tfmd, std::move(terms), params); + } } template <typename VectorizedTerms> @@ -236,19 +230,20 @@ ParallelWeakAndSearch::create(search::fef::TermFieldMatchData &tfmd, // reverse-wrap direct iterators into old API to be compatible with monitoring fef::MatchDataLayout layout; std::vector<fef::TermFieldHandle> handles; + handles.reserve(weights.size()); for (size_t i = 0; i < weights.size(); ++i) { handles.push_back(layout.allocTermField(tfmd.getFieldId())); } fef::MatchData::UP childrenMatchData = layout.createMatchData(); assert(childrenMatchData->getNumTermFields() == dict_entries.size()); wand::Terms terms; + terms.reserve(dict_entries.size()); for (size_t i = 0; i < dict_entries.size(); ++i) { - terms.push_back(wand::Term(new DocidWithWeightSearchIterator(*(childrenMatchData->resolveTermField(handles[i])), attr, dict_entries[i]), - weights[i], - dict_entries[i].posting_size, - childrenMatchData->resolveTermField(handles[i]))); + terms.emplace_back(new DocidWithWeightSearchIterator(*(childrenMatchData->resolveTermField(handles[i])), attr, dict_entries[i]), + weights[i], + dict_entries[i].posting_size, + childrenMatchData->resolveTermField(handles[i])); } - assert(terms.size() == dict_entries.size()); return create(terms, matchParams, RankParams(tfmd, std::move(childrenMatchData)), strict); } } diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.h b/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.h index 9431b527510..ed8d4b4e4ac 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.h +++ b/searchlib/src/vespa/searchlib/queryeval/wand/wand_parts.h @@ -26,7 +26,6 @@ using ref_t = uint16_t; using Attr = IDirectPostingStore; using AttrDictEntry = Attr::LookupResult; -using AttrDictEntries = std::vector<AttrDictEntry>; //----------------------------------------------------------------------------- @@ -55,14 +54,14 @@ struct Term { namespace { struct Ident { - template <typename T> T operator()(const T &t) const { return t; } + template <typename T> T operator()(const T &t) const noexcept { return t; } }; struct NumericOrder { size_t my_size; - NumericOrder(size_t my_size_in) : my_size(my_size_in) {} - size_t size() const { return my_size; } - ref_t operator[](size_t idx) const { return idx; } + explicit NumericOrder(size_t my_size_in) noexcept : my_size(my_size_in) {} + size_t size() const noexcept { return my_size; } + ref_t operator[](size_t idx) const noexcept { return idx; } }; template <typename F, typename Order> @@ -84,25 +83,25 @@ int32_t get_max_weight(const SearchIterator &search) { struct TermInput { const Terms &terms; - TermInput(const Terms &terms_in) : terms(terms_in) {} - size_t size() const { return terms.size(); } - int32_t get_weight(ref_t ref) const { return terms[ref].weight; } - uint32_t get_est_hits(ref_t ref) const { return terms[ref].estHits; } - int32_t get_max_weight(ref_t ref) const { return ::search::queryeval::wand::get_max_weight(*(terms[ref].search)); } - docid_t get_initial_docid(ref_t ref) const { return terms[ref].search->getDocId(); } + explicit TermInput(const Terms &terms_in) noexcept : terms(terms_in) {} + size_t size() const noexcept { return terms.size(); } + int32_t get_weight(ref_t ref) const noexcept { return terms[ref].weight; } + uint32_t get_est_hits(ref_t ref) const noexcept { return terms[ref].estHits; } + int32_t get_max_weight(ref_t ref) const noexcept { return ::search::queryeval::wand::get_max_weight(*(terms[ref].search)); } + docid_t get_initial_docid(ref_t ref) const noexcept { return terms[ref].search->getDocId(); } }; struct AttrInput { const std::vector<int32_t> &weights; const std::vector<IDirectPostingStore::LookupResult> &dict_entries; AttrInput(const std::vector<int32_t> &weights_in, - const std::vector<IDirectPostingStore::LookupResult> &dict_entries_in) + const std::vector<IDirectPostingStore::LookupResult> &dict_entries_in) noexcept : weights(weights_in), dict_entries(dict_entries_in) {} - size_t size() const { return weights.size(); } - int32_t get_weight(ref_t ref) const { return weights[ref]; } - uint32_t get_est_hits(ref_t ref) const { return dict_entries[ref].posting_size; } - int32_t get_max_weight(ref_t ref) const { return dict_entries[ref].max_weight; } - docid_t get_initial_docid(ref_t) const { return SearchIterator::beginId(); } + size_t size() const noexcept { return weights.size(); } + int32_t get_weight(ref_t ref) const noexcept { return weights[ref]; } + uint32_t get_est_hits(ref_t ref) const noexcept { return dict_entries[ref].posting_size; } + int32_t get_max_weight(ref_t ref) const noexcept { return dict_entries[ref].max_weight; } + docid_t get_initial_docid(ref_t) const noexcept { return SearchIterator::beginId(); } }; template <typename Input> @@ -111,7 +110,7 @@ struct MaxSkipOrder { const Input &input; const std::vector<score_t> &max_score; MaxSkipOrder(docid_t docIdLimit, const Input &input_in, - const std::vector<score_t> &max_score_in) + const std::vector<score_t> &max_score_in) noexcept : estNumDocs(1.0), input(input_in), max_score(max_score_in) { estNumDocs = std::max(estNumDocs, docIdLimit - 1.0); @@ -119,10 +118,10 @@ struct MaxSkipOrder { estNumDocs = std::max(estNumDocs, (double)input.get_est_hits(i)); } } - double p_not_hit(double estHits) const { + double p_not_hit(double estHits) const noexcept { return ((estNumDocs - estHits) / (estNumDocs)); } - bool operator()(ref_t a, ref_t b) const { + bool operator()(ref_t a, ref_t b) const noexcept { return ((p_not_hit(input.get_est_hits(a)) * max_score[a]) > (p_not_hit(input.get_est_hits(b)) * max_score[b])); } }; @@ -158,7 +157,7 @@ private: IteratorPack _iteratorPack; public: - VectorizedState(); + VectorizedState() noexcept; VectorizedState(VectorizedState &&) noexcept; VectorizedState & operator=(VectorizedState &&) noexcept; ~VectorizedState(); @@ -184,7 +183,7 @@ public: }; template <typename IteratorPack> -VectorizedState<IteratorPack>::VectorizedState() +VectorizedState<IteratorPack>::VectorizedState() noexcept : _docId(), _weight(), _maxScore(), @@ -292,10 +291,10 @@ struct VectorizedAttributeTerms : VectorizedState<DocidWithWeightIteratorPack> { **/ struct DocIdOrder { const docid_t *termPos; - DocIdOrder(docid_t *pos) : termPos(pos) {} - bool at_end(ref_t ref) const { return termPos[ref] == search::endDocId; } - docid_t get_pos(ref_t ref) const { return termPos[ref]; } - bool operator()(ref_t a, ref_t b) const { + explicit DocIdOrder(docid_t *pos) noexcept : termPos(pos) {} + bool at_end(ref_t ref) const noexcept { return termPos[ref] == search::endDocId; } + docid_t get_pos(ref_t ref) const noexcept { return termPos[ref]; } + bool operator()(ref_t a, ref_t b) const noexcept { return (termPos[a] < termPos[b]); } }; @@ -358,7 +357,7 @@ DualHeap<FutureHeap, PastHeap>::DualHeap(const DocIdOrder &futureCmp, size_t siz } template <typename FutureHeap, typename PastHeap> -DualHeap<FutureHeap, PastHeap>::~DualHeap() { } +DualHeap<FutureHeap, PastHeap>::~DualHeap() = default; template <typename FutureHeap, typename PastHeap> void @@ -399,11 +398,11 @@ DualHeap<FutureHeap, PastHeap>::stringify() const { struct TermFrequencyScorer { // weight * idf, scaled to fixedpoint - static score_t calculateMaxScore(double estHits, double weight) { + static score_t calculateMaxScore(double estHits, double weight) noexcept { return (score_t) (TermFrequencyScorer_TERM_SCORE_FACTOR * weight / (1.0 + log(1.0 + (estHits / 1000.0)))); } - static score_t calculateMaxScore(const Term &term) { + static score_t calculateMaxScore(const Term &term) noexcept { return calculateMaxScore(term.estHits, term.weight) + 1; } @@ -424,9 +423,9 @@ struct DotProductScorer static score_t calculateMaxScore(const Term &term) { int32_t maxWeight = std::numeric_limits<int32_t>::max(); const PostingInfo *postingInfo = term.search->getPostingInfo(); - if (postingInfo != NULL) { - const MinMaxPostingInfo *minMax = dynamic_cast<const MinMaxPostingInfo *>(postingInfo); - if (minMax != NULL) { + if (postingInfo != nullptr) { + const auto *minMax = dynamic_cast<const MinMaxPostingInfo *>(postingInfo); + if (minMax != nullptr) { maxWeight = minMax->getMaxWeight(); } } diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp b/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp index f915a7df335..375a6598b49 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.cpp @@ -109,9 +109,9 @@ SearchIterator::UP WeakAndSearch::createArrayWand(const Terms &terms, uint32_t n, bool strict) { if (strict) { - return SearchIterator::UP(new wand::WeakAndSearchLR<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, true>(terms, n)); + return std::make_unique<wand::WeakAndSearchLR<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, true>>(terms, n); } else { - return SearchIterator::UP(new wand::WeakAndSearchLR<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, false>(terms, n)); + return std::make_unique<wand::WeakAndSearchLR<vespalib::LeftArrayHeap, vespalib::RightArrayHeap, false>>(terms, n); } } @@ -119,9 +119,9 @@ SearchIterator::UP WeakAndSearch::createHeapWand(const Terms &terms, uint32_t n, bool strict) { if (strict) { - return SearchIterator::UP(new wand::WeakAndSearchLR<vespalib::LeftHeap, vespalib::RightHeap, true>(terms, n)); + return std::make_unique<wand::WeakAndSearchLR<vespalib::LeftHeap, vespalib::RightHeap, true>>(terms, n); } else { - return SearchIterator::UP(new wand::WeakAndSearchLR<vespalib::LeftHeap, vespalib::RightHeap, false>(terms, n)); + return std::make_unique<wand::WeakAndSearchLR<vespalib::LeftHeap, vespalib::RightHeap, false>>(terms, n); } } diff --git a/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.h b/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.h index cda5f4c4232..6a56a04887c 100644 --- a/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.h +++ b/searchlib/src/vespa/searchlib/queryeval/wand/weak_and_search.h @@ -2,11 +2,10 @@ #pragma once -#include <vespa/searchlib/queryeval/searchiterator.h> #include "wand_parts.h" +#include <vespa/searchlib/queryeval/searchiterator.h> -namespace search { -namespace queryeval { +namespace search::queryeval { struct WeakAndSearch : SearchIterator { using Terms = wand::Terms; @@ -21,6 +20,4 @@ struct WeakAndSearch : SearchIterator { static SearchIterator::UP create(const Terms &terms, uint32_t n, bool strict); }; -} // namespace queryeval -} // namespace search - +} diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.h b/vespalib/src/vespa/vespalib/btree/btreeiterator.h index a0d189ef03c..505ad4c5c3b 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.h +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.h @@ -39,7 +39,7 @@ class NodeElement using DataType = typename NodeType::DataType; uint64_t _nodeAndIdx; - NodeType * getWNode() const { return const_cast<NodeType *>(getNode()); } + NodeType * getWNode() const noexcept { return const_cast<NodeType *>(getNode()); } static constexpr uint8_t NODE_BITS = 57; static constexpr uint8_t IDX_BITS = 64 - NODE_BITS; static constexpr uint64_t NODE_MASK = (1ul << NODE_BITS) - 1ul; @@ -162,12 +162,12 @@ private: /* * Find the next leaf node, called by operator++() as needed. */ - void findNextLeafNode(); + void findNextLeafNode() noexcept; /* * Find the previous leaf node, called by operator--() as needed. */ - void findPrevLeafNode(); + void findPrevLeafNode() noexcept; protected: /* @@ -175,7 +175,7 @@ protected: * * @param pidx Number of levels above leaf nodes to take into account. */ - size_t position(uint32_t pidx) const; + size_t position(uint32_t pidx) const noexcept; /** * Create iterator pointing to first element in the tree referenced @@ -184,7 +184,7 @@ protected: * @param root Reference to root of tree * @param allocator B-tree node allocator helper class. */ - BTreeIteratorBase(BTreeNode::Ref root, const NodeAllocatorType &allocator); + BTreeIteratorBase(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept; /** * Compability constructor, creating a temporary tree with only a @@ -204,7 +204,7 @@ protected: /** * Step iterator forwards. If at end then leave it at end. */ - BTreeIteratorBase & operator++() { + BTreeIteratorBase & operator++() noexcept { if (_leaf.getNode() == nullptr) { return *this; } @@ -220,7 +220,7 @@ protected: * Step iterator backwards. If at end then place it at last valid * position in tree (cf. rbegin()) */ - BTreeIteratorBase & operator--() { + BTreeIteratorBase & operator--() noexcept { if (_leaf.getNode() == nullptr) { rbegin(); return *this; @@ -233,17 +233,17 @@ protected: return *this; } - void set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position); + void set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position) noexcept; /* * Step iterator forwards the given number of steps. */ - void step_forward(size_t steps); + void step_forward(size_t steps) noexcept; /* * Step iterator backwards the given number of steps. */ - void step_backward(size_t steps); + void step_backward(size_t steps) noexcept; ~BTreeIteratorBase(); BTreeIteratorBase(const BTreeIteratorBase &other); @@ -256,7 +256,7 @@ protected: * * @param pathSize New tree height (number of levels of internal nodes) */ - void clearPath(uint32_t pathSize); + void clearPath(uint32_t pathSize) noexcept; /** * Call func with leaf entry key value as argument for all leaf entries in subtree @@ -347,12 +347,12 @@ public: /** * Return the current position in the tree. */ - size_t position() const { return position(_pathSize); } + size_t position() const noexcept { return position(_pathSize); } /** * Return the distance between two positions in the tree. */ - ssize_t operator-(const BTreeIteratorBase &rhs) const; + ssize_t operator-(const BTreeIteratorBase &rhs) const noexcept; /** * Return if the tree has data or not (e.g. keys and data or only keys). @@ -362,12 +362,14 @@ public: /** * Move the iterator directly to end. Used by findHelper method in BTree. */ - void setupEnd(); + void setupEnd() noexcept { + _leaf.invalidate(); + } /** * Setup iterator to be empty and not be associated with any tree. */ - void setupEmpty() { + void setupEmpty() noexcept { clearPath(0u); _leaf.invalidate(); _leafRoot = nullptr; @@ -376,44 +378,43 @@ public: /** * Move iterator to beyond last element in the current tree. */ - void end() __attribute__((noinline)); + void end() noexcept __attribute__((noinline)); /** * Move iterator to beyond last element in the given tree. * * @param rootRef Reference to root of tree. */ - void end(BTreeNode::Ref rootRef); + void end(BTreeNode::Ref rootRef) noexcept; /** * Move iterator to first element in the current tree. */ - void begin(); + void begin() noexcept; /** * Move iterator to first element in the given tree. * * @param rootRef Reference to root of tree. */ - void begin(BTreeNode::Ref rootRef); + void begin(BTreeNode::Ref rootRef) noexcept; /** * Move iterator to last element in the current tree. */ - void rbegin(); + void rbegin() noexcept; /* * Get aggregated values for the current tree. */ - const AggrT & getAggregated() const; + const AggrT & getAggregated() const noexcept; - bool identical(const BTreeIteratorBase &rhs) const; + bool identical(const BTreeIteratorBase &rhs) const noexcept; template <typename FunctionType> - void foreach_key(FunctionType func) const { + void foreach_key(FunctionType func) const noexcept { if (_pathSize > 0) { - _path[_pathSize - 1].getNode()-> - foreach_key(_allocator->getNodeStore(), func); + _path[_pathSize - 1].getNode()->foreach_key(_allocator->getNodeStore(), func); } else if (_leafRoot != nullptr) { _leafRoot->foreach_key(func); } @@ -425,7 +426,7 @@ public: * range [this iterator, end_itr)). */ template <typename FunctionType> - void foreach_key_range(const BTreeIteratorBase &end_itr, FunctionType func) const { + void foreach_key_range(const BTreeIteratorBase &end_itr, FunctionType func) const noexcept { if (!valid()) { return; } @@ -536,7 +537,7 @@ public: * @param root Reference to root of tree * @param allocator B-tree node allocator helper class. */ - BTreeConstIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) + BTreeConstIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept : ParentType(root, allocator) { } @@ -562,7 +563,7 @@ public: /** * Step iterator forwards. If at end then leave it at end. */ - BTreeConstIterator & operator++() { + BTreeConstIterator & operator++() noexcept { ParentType::operator++(); return *this; } @@ -571,7 +572,7 @@ public: * Step iterator backwards. If at end then place it at last valid * position in tree (cf. rbegin()) */ - BTreeConstIterator & operator--() { + BTreeConstIterator & operator--() noexcept { ParentType::operator--(); return *this; } @@ -579,7 +580,7 @@ public: /* * Step iterator forwards the given number of steps. */ - BTreeConstIterator & operator+=(size_t steps) { + BTreeConstIterator & operator+=(size_t steps) noexcept { step_forward(steps); return *this; } @@ -587,7 +588,7 @@ public: /* * Step iterator backward the given number of steps. */ - BTreeConstIterator & operator-=(size_t steps) { + BTreeConstIterator & operator-=(size_t steps) noexcept { step_backward(steps); return *this; } @@ -599,7 +600,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void lower_bound(const KeyType & key, CompareT comp = CompareT()); + void lower_bound(const KeyType & key, CompareT comp = CompareT()) noexcept; /** * Position iterator at first position with a key that is greater @@ -608,7 +609,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp = CompareT()); + void lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -621,7 +622,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void seek(const KeyType &key, CompareT comp = CompareT()); + void seek(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -633,7 +634,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void binarySeek(const KeyType &key, CompareT comp = CompareT()); + void binarySeek(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -645,7 +646,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void linearSeek(const KeyType &key, CompareT comp = CompareT()); + void linearSeek(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -658,7 +659,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void seekPast(const KeyType &key, CompareT comp = CompareT()); + void seekPast(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -670,7 +671,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void binarySeekPast(const KeyType &key, CompareT comp = CompareT()); + void binarySeekPast(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Step iterator forwards until it is at a position with a key @@ -682,7 +683,7 @@ public: * @param key Key to search for * @param comp Comparator for the tree ordering. */ - void linearSeekPast(const KeyType &key, CompareT comp = CompareT()); + void linearSeekPast(const KeyType &key, CompareT comp = CompareT()) noexcept; /** * Validate the iterator as a valid iterator or positioned at @@ -692,7 +693,7 @@ public: * @param rootRef Reference to root of tree to operate on * @param comp Comparator for the tree ordering. */ - void validate(BTreeNode::Ref rootRef, CompareT comp = CompareT()); + void validate(BTreeNode::Ref rootRef, CompareT comp = CompareT()) noexcept; }; @@ -737,7 +738,7 @@ public: using ParentType::step_forward; using EntryRef = datastore::EntryRef; - BTreeIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) + BTreeIterator(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept : ParentType(root, allocator) { } @@ -751,29 +752,29 @@ public: { } - BTreeIterator() : ParentType() { } + BTreeIterator() noexcept : ParentType() { } - BTreeIterator & operator++() { + BTreeIterator & operator++() noexcept { ParentType::operator++(); return *this; } - BTreeIterator & operator--() { + BTreeIterator & operator--() noexcept { ParentType::operator--(); return *this; } - BTreeIterator & operator+=(size_t steps) { + BTreeIterator & operator+=(size_t steps) noexcept { step_forward(steps); return *this; } - BTreeIterator & operator-=(size_t steps) { + BTreeIterator & operator-=(size_t steps) noexcept { step_backward(steps); return *this; } - NodeAllocatorType & getAllocator() const { + NodeAllocatorType & getAllocator() const noexcept { return const_cast<NodeAllocatorType &>(*_allocator); } @@ -781,19 +782,19 @@ public: void moveNextLeafNode(); - void writeData(const DataType &data) { + void writeData(const DataType &data) noexcept { _leaf.getWNode()->writeData(_leaf.getIdx(), data); } // Only use during compaction when changing reference to moved value - DataType &getWData() { return _leaf.getWData(); } + DataType &getWData() noexcept { return _leaf.getWData(); } /** * Set a new key for the current iterator position. * The new key must have the same semantic meaning as the old key. * Typically used when compacting data store containing keys. */ - void writeKey(const KeyType &key); + void writeKey(const KeyType &key) noexcept; /** * Updata data at the current iterator position. The tree should @@ -803,7 +804,7 @@ public: * @param aggrCalc Calculator for updating aggregated information. */ template <class AggrCalcT> - void updateData(const DataType &data, const AggrCalcT &aggrCalc); + void updateData(const DataType &data, const AggrCalcT &aggrCalc) noexcept; /** * Thaw a path from the root node down the the current leaf node in @@ -816,12 +817,12 @@ private: /* Insert into empty tree */ template <class AggrCalcT> BTreeNode::Ref insertFirst(const KeyType &key, const DataType &data, const AggrCalcT &aggrCalc); - LeafNodeType * getLeafNode() const { return _leaf.getWNode(); } - bool setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode); - void setLeafNodeIdx(uint32_t idx) { _leaf.setIdx(idx); } - uint32_t getLeafNodeIdx() const { return _leaf.getIdx(); } - uint32_t getPathSize() const { return _pathSize; } - PathElement & getPath(uint32_t pidx) { return _path[pidx]; } + LeafNodeType * getLeafNode() const noexcept { return _leaf.getWNode(); } + bool setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) noexcept; + void setLeafNodeIdx(uint32_t idx) noexcept { _leaf.setIdx(idx); } + uint32_t getLeafNodeIdx() const noexcept { return _leaf.getIdx(); } + uint32_t getPathSize() const noexcept { return _pathSize; } + PathElement & getPath(uint32_t pidx) noexcept { return _path[pidx]; } template <class AggrCalcT> BTreeNode::Ref addLevel(BTreeNode::Ref rootRef, BTreeNode::Ref splitNodeRef, bool inRightSplit, const AggrCalcT &aggrCalc); diff --git a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp index bdca5e2c4ff..e1196d7c6db 100644 --- a/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp +++ b/vespalib/src/vespa/vespalib/btree/btreeiterator.hpp @@ -52,7 +52,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -clearPath(uint32_t pathSize) +clearPath(uint32_t pathSize) noexcept { uint32_t level = _pathSize; while (level > pathSize) { @@ -84,18 +84,7 @@ BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>::~B template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void -BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -setupEnd() -{ - _leaf.invalidate(); -} - - -template <typename KeyT, typename DataT, typename AggrT, - uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> -void -BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -end() +BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>::end() noexcept { if (_pathSize == 0) { if (_leafRoot == nullptr) @@ -126,8 +115,7 @@ end() template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void -BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -end(BTreeNode::Ref rootRef) +BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>::end(BTreeNode::Ref rootRef) noexcept { if (!rootRef.valid()) { setupEmpty(); @@ -167,7 +155,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -findNextLeafNode() +findNextLeafNode() noexcept { uint32_t pidx; for (pidx = 0; pidx < _pathSize; ++pidx) { @@ -195,7 +183,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -findPrevLeafNode() +findPrevLeafNode() noexcept { uint32_t pidx; for (pidx = 0; pidx < _pathSize; ++pidx) { @@ -225,8 +213,7 @@ findPrevLeafNode() template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void -BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -begin() +BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>::begin() noexcept { uint32_t pidx = _pathSize; if (pidx > 0u) { @@ -251,8 +238,7 @@ begin() template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void -BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -begin(BTreeNode::Ref rootRef) +BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>::begin(BTreeNode::Ref rootRef) noexcept { if (!rootRef.valid()) { setupEmpty(); @@ -288,8 +274,7 @@ begin(BTreeNode::Ref rootRef) template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void -BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -rbegin() +BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>::rbegin() noexcept { uint32_t pidx = _pathSize; if (pidx > 0u) { @@ -310,10 +295,7 @@ rbegin() const LeafNodeType *lnode(_allocator->mapLeafRef(node)); _leaf.setNodeAndIdx(lnode, lnode->validSlots() - 1); } else { - _leaf.setNodeAndIdx(_leafRoot, - (_leafRoot != nullptr) ? - _leafRoot->validSlots() - 1 : - 0u); + _leaf.setNodeAndIdx(_leafRoot, (_leafRoot != nullptr) ? _leafRoot->validSlots() - 1 : 0u); } } @@ -322,7 +304,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> const AggrT & BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -getAggregated() const +getAggregated() const noexcept { // XXX: Undefined behavior if tree is empty. uint32_t pidx = _pathSize; @@ -340,7 +322,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> size_t BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -position(uint32_t levels) const +position(uint32_t levels) const noexcept { assert(_pathSize >= levels); if (_leaf.getNode() == nullptr) @@ -393,8 +375,7 @@ position(uint32_t levels) const 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>:: -BTreeIteratorBase(BTreeNode::Ref root, - const NodeAllocatorType &allocator) +BTreeIteratorBase(BTreeNode::Ref root, const NodeAllocatorType &allocator) noexcept : _leaf(nullptr, 0u), _path(), _pathSize(0), @@ -467,7 +448,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> ssize_t BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -operator-(const BTreeIteratorBase &rhs) const +operator-(const BTreeIteratorBase &rhs) const noexcept { if (_leaf.getNode() == nullptr) { if (rhs._leaf.getNode() == nullptr) @@ -497,7 +478,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> bool BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -identical(const BTreeIteratorBase &rhs) const +identical(const BTreeIteratorBase &rhs) const noexcept { if (_pathSize != rhs._pathSize || _leaf != rhs._leaf) { HDR_ABORT("should not be reached"); @@ -518,7 +499,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position) +set_subtree_position(const InternalNodeType* node, uint32_t level, uint32_t idx, size_t position) noexcept { /* * Walk down subtree adjusting iterator for new partial position. @@ -550,7 +531,7 @@ template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -step_forward(size_t steps) +step_forward(size_t steps) noexcept { auto lnode = _leaf.getNode(); if (lnode == nullptr) { @@ -600,8 +581,7 @@ step_forward(size_t steps) template <typename KeyT, typename DataT, typename AggrT, uint32_t INTERNAL_SLOTS, uint32_t LEAF_SLOTS, uint32_t PATH_SIZE> void -BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>:: -step_backward(size_t steps) +BTreeIteratorBase<KeyT, DataT, AggrT, INTERNAL_SLOTS, LEAF_SLOTS, PATH_SIZE>::step_backward(size_t steps) noexcept { int64_t remaining_steps = steps; if (remaining_steps == 0) { @@ -651,11 +631,10 @@ step_backward(size_t steps) set_subtree_position(node, level, idx, -remaining_steps); } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -lower_bound(const KeyType & key, CompareT comp) +lower_bound(const KeyType & key, CompareT comp) noexcept { if (_pathSize == 0) { if (_leafRoot == nullptr) @@ -696,11 +675,10 @@ lower_bound(const KeyType & key, CompareT comp) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp) +lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp) noexcept { if (!rootRef.valid()) { setupEmpty(); @@ -748,11 +726,10 @@ lower_bound(BTreeNode::Ref rootRef, const KeyType & key, CompareT comp) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -seek(const KeyType & key, CompareT comp) +seek(const KeyType & key, CompareT comp) noexcept { if (TraitsT::BINARY_SEEK) { binarySeek(key, comp); @@ -761,11 +738,10 @@ seek(const KeyType & key, CompareT comp) } } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -binarySeek(const KeyType & key, CompareT comp) +binarySeek(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -806,11 +782,10 @@ binarySeek(const KeyType & key, CompareT comp) _leaf.setIdx(lidx); } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -linearSeek(const KeyType & key, CompareT comp) +linearSeek(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -858,11 +833,10 @@ linearSeek(const KeyType & key, CompareT comp) _leaf.setIdx(lidx); } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -seekPast(const KeyType & key, CompareT comp) +seekPast(const KeyType & key, CompareT comp) noexcept { if (TraitsT::BINARY_SEEK) { binarySeekPast(key, comp); @@ -871,11 +845,10 @@ seekPast(const KeyType & key, CompareT comp) } } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -binarySeekPast(const KeyType & key, CompareT comp) +binarySeekPast(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -916,11 +889,10 @@ binarySeekPast(const KeyType & key, CompareT comp) _leaf.setIdx(lidx); } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -linearSeekPast(const KeyType & key, CompareT comp) +linearSeekPast(const KeyType & key, CompareT comp) noexcept { const LeafNodeType *lnode = _leaf.getNode(); uint32_t lidx = _leaf.getIdx() + 1; @@ -970,11 +942,10 @@ linearSeekPast(const KeyType & key, CompareT comp) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeConstIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -validate(BTreeNode::Ref rootRef, CompareT comp) +validate(BTreeNode::Ref rootRef, CompareT comp) noexcept { bool frozen = false; if (!rootRef.valid()) { @@ -1036,8 +1007,7 @@ validate(BTreeNode::Ref rootRef, CompareT comp) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> BTreeNode::Ref BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: moveFirstLeafNode(BTreeNode::Ref rootRef) @@ -1100,11 +1070,9 @@ moveFirstLeafNode(BTreeNode::Ref rootRef) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void -BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -moveNextLeafNode() +BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>::moveNextLeafNode() { uint32_t level = 0; uint32_t levels = _pathSize; @@ -1146,11 +1114,9 @@ moveNextLeafNode() } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void -BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -writeKey(const KeyType & key) +BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>::writeKey(const KeyType & key) noexcept { LeafNodeType * lnode = getLeafNode(); lnode->writeKey(_leaf.getIdx(), key); @@ -1170,12 +1136,11 @@ writeKey(const KeyType & key) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> template <class AggrCalcT> void BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) +updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) noexcept { LeafNodeType * lnode = getLeafNode(); if constexpr (AggrCalcT::hasAggregated() && AggrCalcT::aggregate_over_values()) { @@ -1198,8 +1163,7 @@ updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) const PathElement & pe = _path[i]; InternalNodeType * inode = pe.getWNode(); AggrT oldpa(inode->getAggregated()); - if (aggrCalc.update(inode->getAggregated(), - oldca, ca)) { + if (aggrCalc.update(inode->getAggregated(), oldca, ca)) { Aggregator::recalc(*inode, *_allocator, aggrCalc); } AggrT pa(inode->getAggregated()); @@ -1212,11 +1176,9 @@ updateData(const DataType & data, [[maybe_unused]] const AggrCalcT &aggrCalc) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> BTreeNode::Ref -BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -thaw(BTreeNode::Ref rootRef) +BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>::thaw(BTreeNode::Ref rootRef) { assert(_leaf.getNode() != nullptr && _compatLeafNode.get() == nullptr); if (!_leaf.getNode()->getFrozen()) @@ -1226,20 +1188,17 @@ thaw(BTreeNode::Ref rootRef) LeafNodeType *leafNode = allocator.mapLeafRef(rootRef); assert(leafNode == _leaf.getNode()); assert(leafNode == _leafRoot); - LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(rootRef, - leafNode); + LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(rootRef, leafNode); _leaf.setNode(thawedLeaf.data); _leafRoot = thawedLeaf.data; return thawedLeaf.ref; } assert(_leafRoot == nullptr); - assert(_path[_pathSize - 1].getNode() == - allocator.mapInternalRef(rootRef)); + assert(_path[_pathSize - 1].getNode() == allocator.mapInternalRef(rootRef)); BTreeNode::Ref childRef(_path[0].getNode()->getChild(_path[0].getIdx())); LeafNodeType *leafNode = allocator.mapLeafRef(childRef); assert(leafNode == _leaf.getNode()); - LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(childRef, - leafNode); + LeafNodeTypeRefPair thawedLeaf = allocator.thawNode(childRef, leafNode); _leaf.setNode(thawedLeaf.data); childRef = thawedLeaf.ref; uint32_t level = 0; @@ -1247,10 +1206,9 @@ thaw(BTreeNode::Ref rootRef) while (level < levels) { PathElement &pe = _path[level]; InternalNodeType *node(pe.getWNode()); - BTreeNode::Ref nodeRef = level + 1 < levels ? - _path[level + 1].getNode()-> - getChild(_path[level + 1].getIdx()) : - rootRef; + BTreeNode::Ref nodeRef = (level + 1 < levels) + ? _path[level + 1].getNode()->getChild(_path[level + 1].getIdx()) + : rootRef; assert(node == allocator.mapInternalRef(nodeRef)); if (!node->getFrozen()) { node->set_child_relaxed(pe.getIdx(), childRef); @@ -1267,8 +1225,7 @@ thaw(BTreeNode::Ref rootRef) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> template <class AggrCalcT> BTreeNode::Ref BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: @@ -1295,16 +1252,14 @@ insertFirst(const KeyType &key, const DataType &data, } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> bool BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: -setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) +setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) noexcept { uint32_t leafSlots = _leaf.getNode()->validSlots(); if (idx >= leafSlots) { - _leaf.setNodeAndIdx(splitLeafNode, - idx - leafSlots); + _leaf.setNodeAndIdx(splitLeafNode, idx - leafSlots); if (_pathSize == 0) { _leafRoot = splitLeafNode; } @@ -1316,8 +1271,7 @@ setLeafNodeIdx(uint32_t idx, const LeafNodeType *splitLeafNode) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> template <class AggrCalcT> BTreeNode::Ref BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: @@ -1349,8 +1303,7 @@ addLevel(BTreeNode::Ref rootRef, BTreeNode::Ref splitNodeRef, } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> BTreeNode::Ref BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: removeLevel(BTreeNode::Ref rootRef, InternalNodeType *rootNode) @@ -1367,8 +1320,7 @@ removeLevel(BTreeNode::Ref rootRef, InternalNodeType *rootNode) } -template <typename KeyT, typename DataT, typename AggrT, typename CompareT, - typename TraitsT> +template <typename KeyT, typename DataT, typename AggrT, typename CompareT, typename TraitsT> void BTreeIterator<KeyT, DataT, AggrT, CompareT, TraitsT>:: removeLast(BTreeNode::Ref rootRef) diff --git a/vespalib/src/vespa/vespalib/data/memorydatastore.h b/vespalib/src/vespa/vespalib/data/memorydatastore.h index 0bf2becf7c3..3682e3629e3 100644 --- a/vespalib/src/vespa/vespalib/data/memorydatastore.h +++ b/vespalib/src/vespa/vespalib/data/memorydatastore.h @@ -2,7 +2,6 @@ #pragma once #include <vespa/vespalib/util/alloc.h> -#include <vespa/vespalib/util/array.h> #include <vector> #include <mutex> diff --git a/vespalib/src/vespa/vespalib/objects/nbostream.h b/vespalib/src/vespa/vespalib/objects/nbostream.h index ab02e7c1f05..f66c261ae91 100644 --- a/vespalib/src/vespa/vespalib/objects/nbostream.h +++ b/vespalib/src/vespa/vespalib/objects/nbostream.h @@ -107,17 +107,13 @@ public: } template <typename T, typename U> - nbostream & - operator<<(const std::pair<T, U> &val) - { + nbostream & operator<<(const std::pair<T, U> &val) { *this << val.first << val.second; return *this; } template <typename T, typename U> - nbostream & - operator>>(std::pair<T, U> &val) - { + nbostream & operator>>(std::pair<T, U> &val) { *this >> val.first >> val.second; return *this; } |