From 616354ba967daf0579c169b39d24dd8f8d20de20 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Wed, 17 Mar 2021 11:20:44 +0100 Subject: Use IEnumStoreDictionary in IDocumentWeightAttribute implementations. --- .../searchlib/attribute/enum_store_dictionary.cpp | 44 ++++++++++++++++++++++ .../searchlib/attribute/enum_store_dictionary.h | 5 +++ .../searchlib/attribute/i_enum_store_dictionary.h | 3 ++ .../attribute/multinumericpostattribute.hpp | 17 ++++----- .../attribute/multistringpostattribute.hpp | 26 +++++-------- 5 files changed, 68 insertions(+), 27 deletions(-) (limited to 'searchlib') diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp index 0f0b9bfc78d..dd08b2a48b6 100644 --- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp +++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp @@ -129,6 +129,39 @@ EnumStoreDictionary::find_matching_enums(const vespalib::datastore: return result; } +template +EntryRef +EnumStoreDictionary::get_frozen_root() const +{ + return this->_dict.getFrozenView().getRoot(); +} + +template <> +std::pair +EnumStoreDictionary::find_posting_list(const vespalib::datastore::EntryComparator&, EntryRef) const +{ + LOG_ABORT("should not be reached"); +} + +template <> +std::pair +EnumStoreDictionary::find_posting_list(const vespalib::datastore::EntryComparator& cmp, EntryRef root) const +{ + typename DictionaryType::ConstIterator itr(vespalib::btree::BTreeNode::Ref(), this->_dict.getAllocator()); + itr.lower_bound(root, Index(), cmp); + if (itr.valid() && !cmp.less(Index(), itr.getKey())) { + return std::make_pair(itr.getKey(), EntryRef(itr.getData())); + } + return std::make_pair(Index(), EntryRef()); +} + +template +void +EnumStoreDictionary::collect_folded(Index idx, EntryRef, const std::function& callback) const +{ + callback(idx); +} + template IEnumStore::Index EnumStoreDictionary::remap_index(Index idx) @@ -261,6 +294,17 @@ EnumStoreFoldedDictionary::remove(const EntryComparator& comp, EntryRef ref) } } +void +EnumStoreFoldedDictionary::collect_folded(Index idx, EntryRef root, const std::function& callback) const +{ + DictionaryType::ConstIterator itr(vespalib::btree::BTreeNode::Ref(), _dict.getAllocator()); + itr.lower_bound(root, idx, *_folded_compare); + while (itr.valid() && !_folded_compare->less(idx, itr.getKey())) { + callback(itr.getKey()); + ++itr; + } +} + IEnumStore::Index EnumStoreFoldedDictionary::remap_index(Index idx) { diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h index 085806e3446..77caeed1b2d 100644 --- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h +++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h @@ -17,6 +17,7 @@ class EnumStoreDictionary : public vespalib::datastore::UniqueStoreDictionary find_matching_enums(const vespalib::datastore::EntryComparator& cmp) const override; + EntryRef get_frozen_root() const override; + std::pair find_posting_list(const vespalib::datastore::EntryComparator& cmp, EntryRef root) const override; + void collect_folded(Index idx, EntryRef root, const std::function& callback) const override; Index remap_index(Index idx) override; void clear_all_posting_lists(std::function clearer) override; void update_posting_list(Index idx, const vespalib::datastore::EntryComparator& cmp, std::function updater) override; @@ -75,6 +79,7 @@ public: ~EnumStoreFoldedDictionary() override; vespalib::datastore::UniqueStoreAddResult add(const vespalib::datastore::EntryComparator& comp, std::function insertEntry) override; void remove(const vespalib::datastore::EntryComparator& comp, vespalib::datastore::EntryRef ref) override; + void collect_folded(Index idx, EntryRef root, const std::function& callback) const override; Index remap_index(Index idx) override; }; diff --git a/searchlib/src/vespa/searchlib/attribute/i_enum_store_dictionary.h b/searchlib/src/vespa/searchlib/attribute/i_enum_store_dictionary.h index 2abb91f94a6..968d1fa8747 100644 --- a/searchlib/src/vespa/searchlib/attribute/i_enum_store_dictionary.h +++ b/searchlib/src/vespa/searchlib/attribute/i_enum_store_dictionary.h @@ -47,6 +47,9 @@ public: virtual std::vector find_matching_enums(const vespalib::datastore::EntryComparator& cmp) const = 0; + virtual EntryRef get_frozen_root() const = 0; + virtual std::pair find_posting_list(const vespalib::datastore::EntryComparator& cmp, EntryRef root) const = 0; + virtual void collect_folded(Index idx, EntryRef root, const std::function& callback) const = 0; virtual Index remap_index(Index idx) = 0; virtual void clear_all_posting_lists(std::function clearer) = 0; virtual void update_posting_list(Index idx, const vespalib::datastore::EntryComparator& cmp, std::function updater) = 0; diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp index ed19e6ae0ba..f91dac630d3 100644 --- a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp @@ -86,29 +86,26 @@ template vespalib::datastore::EntryRef MultiValueNumericPostingAttribute::DocumentWeightAttributeAdapter::get_dictionary_snapshot() const { - const Dictionary &dictionary = self._enumStore.get_posting_dictionary(); - return dictionary.getFrozenView().getRoot(); + const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); + return dictionary.get_frozen_root(); } template IDocumentWeightAttribute::LookupResult MultiValueNumericPostingAttribute::DocumentWeightAttributeAdapter::lookup(const vespalib::string &term, vespalib::datastore::EntryRef dictionary_snapshot) const { - const Dictionary &dictionary = self._enumStore.get_posting_dictionary(); - DictionaryConstIterator dictItr(vespalib::btree::BTreeNode::Ref(), dictionary.getAllocator()); - + const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); char *end = nullptr; int64_t int_term = strtoll(term.c_str(), &end, 10); if (*end == '\0') { auto comp = self._enumStore.make_comparator(int_term); - - dictItr.lower_bound(dictionary_snapshot, EnumIndex(), comp); - if (dictItr.valid() && !comp.less(EnumIndex(), dictItr.getKey())) { - vespalib::datastore::EntryRef pidx(dictItr.getData()); + auto find_result = dictionary.find_posting_list(comp, dictionary_snapshot); + if (find_result.first.valid()) { + auto pidx = find_result.second; if (pidx.valid()) { const PostingList &plist = self.getPostingList(); auto minmax = plist.getAggregated(pidx); - return LookupResult(pidx, plist.frozenSize(pidx), minmax.getMin(), minmax.getMax(), dictItr.getKey()); + return LookupResult(pidx, plist.frozenSize(pidx), minmax.getMin(), minmax.getMax(), find_result.first); } } } diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp index afd7da6911d..7dea95b2e55 100644 --- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp @@ -102,25 +102,23 @@ template vespalib::datastore::EntryRef MultiValueStringPostingAttributeT::DocumentWeightAttributeAdapter::get_dictionary_snapshot() const { - const Dictionary &dictionary = self._enumStore.get_posting_dictionary(); - return dictionary.getFrozenView().getRoot(); + const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); + return dictionary.get_frozen_root(); } template IDocumentWeightAttribute::LookupResult MultiValueStringPostingAttributeT::DocumentWeightAttributeAdapter::lookup(const vespalib::string &term, vespalib::datastore::EntryRef dictionary_snapshot) const { - const Dictionary &dictionary = self._enumStore.get_posting_dictionary(); - Dictionary::ConstIterator dictItr(vespalib::btree::BTreeNode::Ref(), dictionary.getAllocator()); + const IEnumStoreDictionary& dictionary = self._enumStore.get_dictionary(); auto comp = self._enumStore.make_folded_comparator(term.c_str()); - - dictItr.lower_bound(dictionary_snapshot, enumstore::Index(), comp); - if (dictItr.valid() && !comp.less(enumstore::Index(), dictItr.getKey())) { - vespalib::datastore::EntryRef pidx(dictItr.getData()); + auto find_result = dictionary.find_posting_list(comp, dictionary_snapshot); + if (find_result.first.valid()) { + auto pidx = find_result.second; if (pidx.valid()) { const PostingList &plist = self.getPostingList(); auto minmax = plist.getAggregated(pidx); - return LookupResult(pidx, plist.frozenSize(pidx), minmax.getMin(), minmax.getMax(), dictItr.getKey()); + return LookupResult(pidx, plist.frozenSize(pidx), minmax.getMin(), minmax.getMax(), find_result.first); } } return LookupResult(); @@ -130,14 +128,8 @@ template void MultiValueStringPostingAttributeT::DocumentWeightAttributeAdapter::collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function& callback) const { - const Dictionary &dictionary = self._enumStore.get_posting_dictionary(); - Dictionary::ConstIterator dictItr(vespalib::btree::BTreeNode::Ref(), dictionary.getAllocator()); - auto comp = self._enumStore.make_folded_comparator(); - dictItr.lower_bound(dictionary_snapshot, enum_idx, comp); - while (dictItr.valid() && !comp.less(enum_idx, dictItr.getKey())) { - callback(dictItr.getKey()); - ++dictItr; - } + const IEnumStoreDictionary &dictionary = self._enumStore.get_dictionary(); + dictionary.collect_folded(enum_idx, dictionary_snapshot, callback); } template -- cgit v1.2.3