summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@broadpark.no>2021-03-17 11:20:44 +0100
committerTor Egge <Tor.Egge@broadpark.no>2021-03-17 11:20:44 +0100
commit616354ba967daf0579c169b39d24dd8f8d20de20 (patch)
tree30564ed75bbffd18699ebf0e69b69b228d2b5498 /searchlib
parente91a0341b66180d8a0ac8f1a8f17b0fcd4e5a30f (diff)
Use IEnumStoreDictionary in IDocumentWeightAttribute implementations.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp44
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.h5
-rw-r--r--searchlib/src/vespa/searchlib/attribute/i_enum_store_dictionary.h3
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp17
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp26
5 files changed, 68 insertions, 27 deletions
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
@@ -130,6 +130,39 @@ EnumStoreDictionary<DictionaryT>::find_matching_enums(const vespalib::datastore:
}
template <typename DictionaryT>
+EntryRef
+EnumStoreDictionary<DictionaryT>::get_frozen_root() const
+{
+ return this->_dict.getFrozenView().getRoot();
+}
+
+template <>
+std::pair<IEnumStore::Index, EntryRef>
+EnumStoreDictionary<EnumTree>::find_posting_list(const vespalib::datastore::EntryComparator&, EntryRef) const
+{
+ LOG_ABORT("should not be reached");
+}
+
+template <>
+std::pair<IEnumStore::Index, EntryRef>
+EnumStoreDictionary<EnumPostingTree>::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 <typename DictionaryT>
+void
+EnumStoreDictionary<DictionaryT>::collect_folded(Index idx, EntryRef, const std::function<void(vespalib::datastore::EntryRef)>& callback) const
+{
+ callback(idx);
+}
+
+template <typename DictionaryT>
IEnumStore::Index
EnumStoreDictionary<DictionaryT>::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<void(vespalib::datastore::EntryRef)>& 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<Di
protected:
using EntryRef = IEnumStoreDictionary::EntryRef;
using Index = IEnumStoreDictionary::Index;
+ using DictionaryType = DictionaryT;
private:
using EnumVector = IEnumStoreDictionary::EnumVector;
using IndexSet = IEnumStoreDictionary::IndexSet;
@@ -49,6 +50,9 @@ public:
std::vector<attribute::IAttributeVector::EnumHandle>
find_matching_enums(const vespalib::datastore::EntryComparator& cmp) const override;
+ EntryRef get_frozen_root() const override;
+ std::pair<Index, EntryRef> find_posting_list(const vespalib::datastore::EntryComparator& cmp, EntryRef root) const override;
+ void collect_folded(Index idx, EntryRef root, const std::function<void(vespalib::datastore::EntryRef)>& callback) 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;
@@ -75,6 +79,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;
+ void collect_folded(Index idx, EntryRef root, const std::function<void(vespalib::datastore::EntryRef)>& 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<attribute::IAttributeVector::EnumHandle>
find_matching_enums(const vespalib::datastore::EntryComparator& cmp) const = 0;
+ virtual EntryRef get_frozen_root() const = 0;
+ virtual std::pair<Index, EntryRef> find_posting_list(const vespalib::datastore::EntryComparator& cmp, EntryRef root) const = 0;
+ virtual void collect_folded(Index idx, EntryRef root, const std::function<void(vespalib::datastore::EntryRef)>& callback) 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;
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 <typename B, typename M>
vespalib::datastore::EntryRef
MultiValueNumericPostingAttribute<B, M>::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 <typename B, typename M>
IDocumentWeightAttribute::LookupResult
MultiValueNumericPostingAttribute<B, M>::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 <typename B, typename T>
vespalib::datastore::EntryRef
MultiValueStringPostingAttributeT<B, T>::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 <typename B, typename T>
IDocumentWeightAttribute::LookupResult
MultiValueStringPostingAttributeT<B, T>::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 <typename B, typename T>
void
MultiValueStringPostingAttributeT<B, T>::DocumentWeightAttributeAdapter::collect_folded(vespalib::datastore::EntryRef enum_idx, vespalib::datastore::EntryRef dictionary_snapshot, const std::function<void(vespalib::datastore::EntryRef)>& 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 <typename B, typename T>