diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2021-03-18 16:43:47 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2021-03-18 16:43:47 +0100 |
commit | a2d99ca3b74ea6568624d7ce252694016bcea33d (patch) | |
tree | 1e9b1b98270dd5bb9e0b905a89bfe611365a9124 /searchlib | |
parent | de87b1f0eeffe3963c2f22cc4d5e55166e519380 (diff) |
Update unordered dictionary.
Diffstat (limited to 'searchlib')
4 files changed, 27 insertions, 1 deletions
diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp index 34e913a4c07..18e34c89ad0 100644 --- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp +++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp @@ -89,6 +89,10 @@ EnumStoreDictionary<DictionaryT, UnorderedDictionaryT>::remove(const EntryCompar assert(EntryRef(itr.getData()) == EntryRef()); } this->_dict.remove(itr); + if constexpr (has_unordered_dictionary) { + auto *result = this->_unordered_dict.remove(comp, ref); + assert(result != nullptr && result->first.load_relaxed() == ref); + } } template <typename DictionaryT, typename UnorderedDictionaryT> @@ -217,6 +221,21 @@ EnumStoreDictionary<DictionaryT, UnorderedDictionaryT>::update_posting_list(Inde itr.writeData(new_posting_idx.ref()); } +template <typename DictionaryT, typename UnorderedDictionaryT> +void +EnumStoreDictionary<DictionaryT, UnorderedDictionaryT>::sync_unordered_after_load() +{ + if constexpr (has_unordered_dictionary) { + for (auto itr = this->_dict.begin(); itr.valid(); ++itr) { + EntryRef ref(itr.getKey()); + std::function<EntryRef(void)> insert_unordered_entry([ref]() -> EntryRef { return ref; }); + auto& add_result = this->_unordered_dict.add(this->_unordered_dict.get_default_comparator(), ref, insert_unordered_entry); + assert(add_result.first.load_relaxed() == ref); + add_result.second.store_relaxed(EntryRef(itr.getData())); + } + } +} + template <> EnumPostingTree & EnumStoreDictionary<EnumTree>::get_posting_dictionary() @@ -256,6 +275,7 @@ EnumStoreFoldedDictionary::~EnumStoreFoldedDictionary() = default; UniqueStoreAddResult EnumStoreFoldedDictionary::add(const EntryComparator& comp, std::function<EntryRef(void)> insertEntry) { + static_assert(!has_unordered_dictionary, "Folded Dictionary does not support unordered"); auto it = _dict.lowerBound(EntryRef(), comp); if (it.valid() && !comp.less(EntryRef(), it.getKey())) { // Entry already exists @@ -279,6 +299,7 @@ EnumStoreFoldedDictionary::add(const EntryComparator& comp, std::function<EntryR void EnumStoreFoldedDictionary::remove(const EntryComparator& comp, EntryRef ref) { + static_assert(!has_unordered_dictionary, "Folded Dictionary does not support unordered"); assert(ref.valid()); auto it = _dict.lowerBound(ref, comp); assert(it.valid() && it.getKey() == ref); diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h index 63ccb2efac7..2c2c39451c0 100644 --- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h +++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h @@ -24,7 +24,9 @@ private: using IndexVector = IEnumStoreDictionary::IndexVector; using ParentUniqueStoreDictionary = vespalib::datastore::UniqueStoreDictionary<DictionaryT, IEnumStoreDictionary, UnorderedDictionaryT>; using generation_t = IEnumStoreDictionary::generation_t; - +protected: + using ParentUniqueStoreDictionary::has_unordered_dictionary; +private: IEnumStore& _enumStore; void remove_unused_values(const IndexSet& unused, @@ -56,6 +58,7 @@ public: 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; + void sync_unordered_after_load() override; EnumPostingTree& get_posting_dictionary() override; const EnumPostingTree& get_posting_dictionary() const 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 968d1fa8747..309f037ac84 100644 --- a/searchlib/src/vespa/searchlib/attribute/i_enum_store_dictionary.h +++ b/searchlib/src/vespa/searchlib/attribute/i_enum_store_dictionary.h @@ -53,6 +53,7 @@ public: 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 void sync_unordered_after_load() = 0; virtual EnumPostingTree& get_posting_dictionary() = 0; virtual const EnumPostingTree& get_posting_dictionary() const = 0; }; diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp index d3223901a71..c76571b151d 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp @@ -102,6 +102,7 @@ PostingListAttributeBase<P>::handle_load_posting_lists_and_update_enum_store(enu &postings._removals[0] + postings._removals.size()); posting_itr.writeData(newIndex.ref()); loader.free_unused_values(); + _dictionary.sync_unordered_after_load(); } template <typename P> |