diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-16 16:18:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-16 16:18:28 +0100 |
commit | a1ac91dfcebef06b2ba6a3dce2f980fd9aaa0245 (patch) | |
tree | e33ebb8b8512f19390ed3b55b4dd38ae756c1c33 /searchlib | |
parent | 051a745b86a2a6ba1ee7e41a171a2955fcb69ca3 (diff) | |
parent | 03f84a67cdf5d1a6231e71fad028e4750fbf7078 (diff) |
Merge pull request #16982 from vespa-engine/toregge/add-key-remapping-to-enum-store-dictionary
Add remap_index member function to IEnumStoreDictionary.
Diffstat (limited to 'searchlib')
6 files changed, 30 insertions, 13 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp index f7a2a507aec..0f0b9bfc78d 100644 --- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp +++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp @@ -129,6 +129,13 @@ EnumStoreDictionary<DictionaryT>::find_matching_enums(const vespalib::datastore: return result; } +template <typename DictionaryT> +IEnumStore::Index +EnumStoreDictionary<DictionaryT>::remap_index(Index idx) +{ + return idx; +} + template <> void EnumStoreDictionary<EnumTree>::clear_all_posting_lists(std::function<void(EntryRef)>) @@ -254,6 +261,14 @@ EnumStoreFoldedDictionary::remove(const EntryComparator& comp, EntryRef ref) } } +IEnumStore::Index +EnumStoreFoldedDictionary::remap_index(Index idx) +{ + auto itr = _dict.find(idx, *_folded_compare); + assert(itr.valid()); + return itr.getKey(); +} + template class EnumStoreDictionary<EnumTree>; template class EnumStoreDictionary<EnumPostingTree>; diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h index 67bbb1cd3e9..085806e3446 100644 --- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h +++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h @@ -16,9 +16,9 @@ template <typename DictionaryT> class EnumStoreDictionary : public vespalib::datastore::UniqueStoreDictionary<DictionaryT, IEnumStoreDictionary> { protected: using EntryRef = IEnumStoreDictionary::EntryRef; + using Index = IEnumStoreDictionary::Index; private: using EnumVector = IEnumStoreDictionary::EnumVector; - using Index = IEnumStoreDictionary::Index; using IndexSet = IEnumStoreDictionary::IndexSet; using IndexVector = IEnumStoreDictionary::IndexVector; using ParentUniqueStoreDictionary = vespalib::datastore::UniqueStoreDictionary<DictionaryT, IEnumStoreDictionary>; @@ -49,6 +49,7 @@ public: std::vector<attribute::IAttributeVector::EnumHandle> find_matching_enums(const vespalib::datastore::EntryComparator& cmp) const override; + Index remap_index(Index idx) override; void clear_all_posting_lists(std::function<void(EntryRef)> clearer) override; void update_posting_list(Index idx, const vespalib::datastore::EntryComparator& cmp, std::function<EntryRef(EntryRef)> updater) override; EnumPostingTree& get_posting_dictionary() override; @@ -74,6 +75,7 @@ public: ~EnumStoreFoldedDictionary() override; vespalib::datastore::UniqueStoreAddResult add(const vespalib::datastore::EntryComparator& comp, std::function<vespalib::datastore::EntryRef(void)> insertEntry) override; void remove(const vespalib::datastore::EntryComparator& comp, vespalib::datastore::EntryRef ref) 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 8bbd7677595..2abb91f94a6 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,7 @@ public: virtual std::vector<attribute::IAttributeVector::EnumHandle> find_matching_enums(const vespalib::datastore::EntryComparator& cmp) const = 0; + virtual Index remap_index(Index idx) = 0; virtual void clear_all_posting_lists(std::function<void(EntryRef)> clearer) = 0; virtual void update_posting_list(Index idx, const vespalib::datastore::EntryComparator& cmp, std::function<EntryRef(EntryRef)> updater) = 0; virtual EnumPostingTree& get_posting_dictionary() = 0; diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp index 29e9ad39073..325874091ef 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp @@ -78,7 +78,7 @@ void SingleValueNumericPostingAttribute<B>::applyValueChanges(EnumStoreBatchUpdater& updater) { EnumStore & enumStore = this->getEnumStore(); - Dictionary & dict = enumStore.get_posting_dictionary(); + IEnumStoreDictionary& dictionary = enumStore.get_dictionary(); auto cmp = enumStore.make_comparator(); PostingMap changePost; @@ -101,9 +101,8 @@ SingleValueNumericPostingAttribute<B>::applyValueChanges(EnumStoreBatchUpdater& if (oldIdx.valid()) { T oldValue = enumStore.get_value(oldIdx); T newValue = this->applyArithmetic(oldValue, change); - - auto addItr = dict.find(EnumIndex(), enumStore.make_comparator(newValue)); - EnumIndex newIdx = addItr.getKey(); + EnumIndex newIdx; + (void) dictionary.find_index(enumStore.make_comparator(newValue), newIdx); currEnumIndices[change._doc] = newIdx; } } else if(change._type == ChangeBase::CLEARDOC) { diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h index 60a4bc022be..397fad60be3 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h @@ -67,7 +67,7 @@ private: void makePostingChange(const vespalib::datastore::EntryComparator *cmp, - Dictionary &dict, + IEnumStoreDictionary& dictionary, const std::map<DocId, EnumIndex> &currEnumIndices, PostingMap &changePost); diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp index e91deb61f36..50ed621b13e 100644 --- a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp @@ -53,7 +53,7 @@ template <typename B> void SingleValueStringPostingAttributeT<B>:: makePostingChange(const vespalib::datastore::EntryComparator *cmpa, - Dictionary &dict, + IEnumStoreDictionary& dictionary, const std::map<DocId, EnumIndex> &currEnumIndices, PostingMap &changePost) { @@ -63,13 +63,13 @@ makePostingChange(const vespalib::datastore::EntryComparator *cmpa, EnumIndex newIdx = elem.second; // add new posting - auto addItr = dict.find(newIdx, *cmpa); - changePost[EnumPostingPair(addItr.getKey(), cmpa)].add(docId, 1); + auto remapped_new_idx = dictionary.remap_index(newIdx); + changePost[EnumPostingPair(remapped_new_idx, cmpa)].add(docId, 1); // remove old posting if ( oldIdx.valid()) { - auto rmItr = dict.find(oldIdx, *cmpa); - changePost[EnumPostingPair(rmItr.getKey(), cmpa)].remove(docId); + auto remapped_old_idx = dictionary.remap_index(oldIdx); + changePost[EnumPostingPair(remapped_old_idx, cmpa)].remove(docId); } } } @@ -79,7 +79,7 @@ void SingleValueStringPostingAttributeT<B>::applyValueChanges(EnumStoreBatchUpdater& updater) { EnumStore & enumStore = this->getEnumStore(); - Dictionary & dict = enumStore.get_posting_dictionary(); + IEnumStoreDictionary& dictionary = enumStore.get_dictionary(); auto cmp = enumStore.make_folded_comparator(); PostingMap changePost; @@ -104,7 +104,7 @@ SingleValueStringPostingAttributeT<B>::applyValueChanges(EnumStoreBatchUpdater& } } - makePostingChange(&cmp, dict, currEnumIndices, changePost); + makePostingChange(&cmp, dictionary, currEnumIndices, changePost); this->updatePostings(changePost); |