summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-04-20 14:16:04 +0200
committerGitHub <noreply@github.com>2021-04-20 14:16:04 +0200
commitddd015ba597fcdadf0a8917a4192534d7ea86cfa (patch)
tree825da3fc49c78be864dc27d42d0a28ad026ca55c /searchlib
parent81af61c96759a3ad3197b3ef56187697302dbec3 (diff)
parent03f03e5ea1df40810ad9a1292b6c7c5ba79c4422 (diff)
Merge pull request #17494 from vespa-engine/balder/various-comparator-cleanup
- Make all use of comparator const.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/attribute/enum_comparator/enum_comparator_test.cpp8
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp57
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumcomparator.h81
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.h41
-rw-r--r--searchlib/src/vespa/searchlib/attribute/enumstore.hpp16
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp5
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp15
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistattribute.h12
-rw-r--r--searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp6
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp4
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h9
-rw-r--r--searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp15
15 files changed, 111 insertions, 172 deletions
diff --git a/searchlib/src/tests/attribute/enum_comparator/enum_comparator_test.cpp b/searchlib/src/tests/attribute/enum_comparator/enum_comparator_test.cpp
index d999a6f37a2..a9efc22dc5a 100644
--- a/searchlib/src/tests/attribute/enum_comparator/enum_comparator_test.cpp
+++ b/searchlib/src/tests/attribute/enum_comparator/enum_comparator_test.cpp
@@ -162,8 +162,8 @@ TEST("requireThatFoldedLessIsWorking")
EXPECT_FALSE(cmp1.less(e2, e1)); // similar folded
EXPECT_TRUE(cmp1.less(e2, e3)); // folded compare
EXPECT_FALSE(cmp1.less(e3, e2)); // folded compare
- auto cmp2 = es.make_folded_comparator("fol", false);
- auto cmp3 = es.make_folded_comparator("fol", true);
+ auto cmp2 = es.make_folded_comparator("fol");
+ auto cmp3 = es.make_folded_comparator_prefix("fol");
EXPECT_TRUE(cmp2.less(EnumIndex(), e4));
EXPECT_FALSE(cmp2.less(e4, EnumIndex()));
EXPECT_FALSE(cmp3.less(EnumIndex(), e4)); // similar when prefix
@@ -183,8 +183,8 @@ TEST("requireThatFoldedEqualIsWorking")
EXPECT_TRUE(cmp1.equal(e2, e1));
EXPECT_FALSE(cmp1.equal(e2, e3)); // folded compare
EXPECT_FALSE(cmp1.equal(e3, e2)); // folded compare
- auto cmp2 = es.make_folded_comparator("fol", false);
- auto cmp3 = es.make_folded_comparator("fol", true);
+ auto cmp2 = es.make_folded_comparator("fol");
+ auto cmp3 = es.make_folded_comparator_prefix("fol");
EXPECT_FALSE(cmp2.equal(EnumIndex(), e4));
EXPECT_FALSE(cmp2.equal(e4, EnumIndex()));
EXPECT_TRUE(cmp2.equal(EnumIndex(), EnumIndex()));
diff --git a/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp b/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp
index a428ac77d87..368de359c85 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumcomparator.cpp
@@ -12,10 +12,9 @@ FoldedStringCompare _strCmp;
}
template <typename EntryT>
-EnumStoreComparator<EntryT>::EnumStoreComparator(const DataStoreType& data_store, const EntryT& fallback_value, bool prefix)
+EnumStoreComparator<EntryT>::EnumStoreComparator(const DataStoreType& data_store, const EntryT& fallback_value)
: ParentType(data_store, fallback_value)
{
- (void) prefix;
}
template <typename EntryT>
@@ -31,52 +30,48 @@ EnumStoreComparator<EntryT>::equal_helper(const EntryT& lhs, const EntryT& rhs)
return vespalib::datastore::UniqueStoreComparatorHelper<EntryT>::equal(lhs, rhs);
}
-EnumStoreStringComparator::EnumStoreStringComparator(const DataStoreType& data_store)
- : ParentType(data_store, nullptr)
-{
-}
-
-EnumStoreStringComparator::EnumStoreStringComparator(const DataStoreType& data_store, const char* fallback_value)
- : ParentType(data_store, fallback_value)
+EnumStoreStringComparator::EnumStoreStringComparator(const DataStoreType& data_store, bool fold)
+ : ParentType(data_store, nullptr),
+ _fold(fold),
+ _prefix(false),
+ _prefix_len(0)
{
}
-EnumStoreFoldedStringComparator::EnumStoreFoldedStringComparator(const DataStoreType& data_store, bool prefix)
- : ParentType(data_store, nullptr),
- _prefix(prefix),
- _prefix_len(0u)
+EnumStoreStringComparator::EnumStoreStringComparator(const DataStoreType& data_store, bool fold, const char* fallback_value)
+ : ParentType(data_store, fallback_value),
+ _fold(fold),
+ _prefix(false),
+ _prefix_len(0)
{
}
-EnumStoreFoldedStringComparator::EnumStoreFoldedStringComparator(const DataStoreType& data_store,
- const char* fallback_value, bool prefix)
+EnumStoreStringComparator::EnumStoreStringComparator(const DataStoreType& data_store, const char* fallback_value, bool prefix)
: ParentType(data_store, fallback_value),
+ _fold(true),
_prefix(prefix),
- _prefix_len(0u)
+ _prefix_len(0)
{
if (use_prefix()) {
_prefix_len = _strCmp.size(fallback_value);
}
}
-int
-EnumStoreStringComparator::compare(const char* lhs, const char* rhs)
-{
- return _strCmp.compare(lhs, rhs);
-}
+bool
+EnumStoreStringComparator::less(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const {
+ return _fold
+ ? (use_prefix()
+ ? (_strCmp.compareFoldedPrefix(get(lhs), get(rhs), _prefix_len) < 0)
+ : (_strCmp.compareFolded(get(lhs), get(rhs)) < 0))
+ : (_strCmp.compare(get(lhs), get(rhs)) < 0);
-int
-EnumStoreFoldedStringComparator::compare_folded(const char* lhs, const char* rhs)
-{
- return _strCmp.compareFolded(lhs, rhs);
}
-int
-EnumStoreFoldedStringComparator::compare_folded_prefix(const char* lhs,
- const char* rhs,
- size_t prefix_len)
-{
- return _strCmp.compareFoldedPrefix(lhs, rhs, prefix_len);
+bool
+EnumStoreStringComparator::equal(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const {
+ return _fold
+ ? (_strCmp.compareFolded(get(lhs), get(rhs)) == 0)
+ : (_strCmp.compare(get(lhs), get(rhs)) == 0);
}
template class EnumStoreComparator<int8_t>;
diff --git a/searchlib/src/vespa/searchlib/attribute/enumcomparator.h b/searchlib/src/vespa/searchlib/attribute/enumcomparator.h
index 0215053ba3a..018ec1b4ff4 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumcomparator.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumcomparator.h
@@ -18,7 +18,7 @@ public:
using ParentType = vespalib::datastore::UniqueStoreComparator<EntryT, IEnumStore::InternalIndex>;
using DataStoreType = typename ParentType::DataStoreType;
- EnumStoreComparator(const DataStoreType& data_store, const EntryT& fallback_value, bool prefix = false);
+ EnumStoreComparator(const DataStoreType& data_store, const EntryT& fallback_value);
EnumStoreComparator(const DataStoreType& data_store);
static bool equal_helper(const EntryT& lhs, const EntryT& rhs);
@@ -34,79 +34,32 @@ class EnumStoreStringComparator : public vespalib::datastore::UniqueStoreStringC
protected:
using ParentType = vespalib::datastore::UniqueStoreStringComparator<IEnumStore::InternalIndex>;
using DataStoreType = ParentType::DataStoreType;
+private:
using ParentType::get;
- static int compare(const char* lhs, const char* rhs);
-
public:
- EnumStoreStringComparator(const DataStoreType& data_store);
+ EnumStoreStringComparator(const DataStoreType& data_store)
+ : EnumStoreStringComparator(data_store, false)
+ {}
+ EnumStoreStringComparator(const DataStoreType& data_store, bool fold);
/**
* Creates a comparator using the given low-level data store and that uses the
* given value during compare if the enum index is invalid.
*/
- EnumStoreStringComparator(const DataStoreType& data_store, const char* fallback_value);
-
- static bool equal(const char* lhs, const char* rhs) {
- return compare(lhs, rhs) == 0;
- }
-
- bool less(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override {
- return compare(get(lhs), get(rhs)) < 0;
- }
- bool equal(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override {
- return compare(get(lhs), get(rhs)) == 0;
- }
-};
-
-
-/**
- * Less-than comparator used for folded-only comparing strings stored in an enum store.
- *
- * The input string values are first folded, then compared.
- * There is NO fallback if they are equal.
- */
-class EnumStoreFoldedStringComparator : public EnumStoreStringComparator {
+ EnumStoreStringComparator(const DataStoreType& data_store, const char* fallback_value)
+ : EnumStoreStringComparator(data_store, false, fallback_value)
+ {}
+ EnumStoreStringComparator(const DataStoreType& data_store, bool fold, const char* fallback_value);
+ EnumStoreStringComparator(const DataStoreType& data_store, const char* fallback_value, bool prefix);
+
+ bool less(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override;
+ bool equal(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override;
private:
- using ParentType = EnumStoreStringComparator;
-
- bool _prefix;
- size_t _prefix_len;
-
inline bool use_prefix() const { return _prefix; }
- static int compare_folded(const char* lhs, const char* rhs);
- static int compare_folded_prefix(const char* lhs, const char* rhs, size_t prefix_len);
-
-public:
- /**
- * Creates a comparator using the given low-level data store.
- *
- * @param prefix whether we should perform prefix compare.
- */
- EnumStoreFoldedStringComparator(const DataStoreType& data_store, bool prefix = false);
-
- /**
- * Creates a comparator using the given low-level data store and that uses the
- * given value during compare if the enum index is invalid.
- *
- * @param prefix whether we should perform prefix compare.
- */
- EnumStoreFoldedStringComparator(const DataStoreType& data_store,
- const char* fallback_value, bool prefix = false);
-
- static bool equal(const char* lhs, const char* rhs) {
- return compare_folded(lhs, rhs) == 0;
- }
-
- bool less(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override {
- if (use_prefix()) {
- return compare_folded_prefix(get(lhs), get(rhs), _prefix_len) < 0;
- }
- return compare_folded(get(lhs), get(rhs)) < 0;
- }
- bool equal(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override {
- return compare_folded(get(lhs), get(rhs)) == 0;
- }
+ const bool _fold;
+ const bool _prefix;
+ uint32_t _prefix_len;
};
extern template class EnumStoreComparator<int8_t>;
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.h b/searchlib/src/vespa/searchlib/attribute/enumstore.h
index 01acee671bc..3d4f6d3e888 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.h
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.h
@@ -43,21 +43,19 @@ public:
vespalib::datastore::UniqueStoreStringAllocator<InternalIndex>,
vespalib::datastore::UniqueStoreAllocator<EntryT, InternalIndex>>;
using UniqueStoreType = vespalib::datastore::UniqueStore<EntryT, InternalIndex, ComparatorType, AllocatorType>;
- using FoldedComparatorType = std::conditional_t<std::is_same_v<EntryT, const char *>,
- EnumStoreFoldedStringComparator,
- ComparatorType>;
+
using EntryType = EntryT;
using EnumStoreType = EnumStoreT<EntryT>;
using EntryRef = vespalib::datastore::EntryRef;
using generation_t = vespalib::GenerationHandler::generation_t;
private:
- UniqueStoreType _store;
- IEnumStoreDictionary* _dict;
- vespalib::MemoryUsage _cached_values_memory_usage;
+ UniqueStoreType _store;
+ IEnumStoreDictionary* _dict;
+ vespalib::MemoryUsage _cached_values_memory_usage;
vespalib::AddressSpace _cached_values_address_space_usage;
- vespalib::MemoryUsage _cached_dictionary_btree_usage;
- vespalib::MemoryUsage _cached_dictionary_hash_usage;
+ vespalib::MemoryUsage _cached_dictionary_btree_usage;
+ vespalib::MemoryUsage _cached_dictionary_hash_usage;
EnumStoreT(const EnumStoreT & rhs) = delete;
EnumStoreT & operator=(const EnumStoreT & rhs) = delete;
@@ -184,18 +182,13 @@ public:
return ComparatorType(_store.get_data_store(), fallback_value);
}
- FoldedComparatorType make_folded_comparator() const {
- return FoldedComparatorType(_store.get_data_store());
- }
-
- FoldedComparatorType make_folded_comparator(const EntryType& fallback_value, bool prefix = false) const {
- return FoldedComparatorType(_store.get_data_store(), fallback_value, prefix);
+ ComparatorType make_folded_comparator() const {
+ return ComparatorType(_store.get_data_store(), true);
}
void write_value(BufferWriter& writer, Index idx) const override;
bool is_folded_change(Index idx1, Index idx2) const override;
bool find_enum(EntryType value, IEnumStore::EnumHandle& e) const;
- std::vector<IEnumStore::EnumHandle> find_folded_enums(EntryType value) const;
Index insert(EntryType value);
bool find_index(EntryType value, Index& idx) const;
void free_unused_values() override;
@@ -212,6 +205,24 @@ public:
}
std::unique_ptr<Enumerator> make_enumerator() const override;
std::unique_ptr<vespalib::datastore::EntryComparator> allocate_comparator() const override;
+
+ // Methods below are only relevant for strings, and are templated to only be instantiated on demand.
+ template <typename Type>
+ ComparatorType
+ make_folded_comparator(const Type& fallback_value) const {
+ return ComparatorType(_store.get_data_store(), true, fallback_value);
+ }
+ template<typename Type>
+ ComparatorType
+ make_folded_comparator_prefix(const Type& fallback_value) const {
+ return ComparatorType(_store.get_data_store(), fallback_value, true);
+ }
+ template<typename Type>
+ std::vector<IEnumStore::EnumHandle>
+ find_folded_enums(Type value) const {
+ auto cmp = make_folded_comparator(value);
+ return _dict->find_matching_enums(cmp);
+ }
};
std::unique_ptr<vespalib::datastore::IUniqueStoreDictionary>
diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
index 0890605f265..de5973dd4a1 100644
--- a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp
@@ -75,7 +75,7 @@ EnumStoreT<EntryT>::EnumStoreT(bool has_postings, const search::DictionaryConfig
_store.set_dictionary(make_enum_store_dictionary(*this, has_postings, dict_cfg,
std::make_unique<ComparatorType>(_store.get_data_store()),
(has_string_type() ?
- std::make_unique<FoldedComparatorType>(_store.get_data_store()) :
+ std::make_unique<ComparatorType>(_store.get_data_store(), true) :
std::unique_ptr<vespalib::datastore::EntryComparator>())));
_dict = static_cast<IEnumStoreDictionary*>(&_store.get_dictionary());
}
@@ -169,14 +169,6 @@ EnumStoreT<EntryT>::find_enum(EntryType value, IEnumStore::EnumHandle& e) const
}
template <typename EntryT>
-std::vector<IEnumStore::EnumHandle>
-EnumStoreT<EntryT>::find_folded_enums(EntryType value) const
-{
- auto cmp = make_folded_comparator(value);
- return _dict->find_matching_enums(cmp);
-}
-
-template <typename EntryT>
bool
EnumStoreT<EntryT>::find_index(EntryType value, Index& idx) const
{
@@ -188,16 +180,14 @@ template <typename EntryT>
void
EnumStoreT<EntryT>::free_unused_values()
{
- auto cmp = make_comparator();
- _dict->free_unused_values(cmp);
+ _dict->free_unused_values(make_comparator());
}
template <typename EntryT>
void
EnumStoreT<EntryT>::free_unused_values(const IndexSet& to_remove)
{
- auto cmp = make_comparator();
- _dict->free_unused_values(to_remove, cmp);
+ _dict->free_unused_values(to_remove, make_comparator());
}
template <typename EntryT>
diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp
index eb54bb07753..5b695c5751b 100644
--- a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp
@@ -27,11 +27,10 @@ MultiValueNumericPostingAttribute<B, M>::applyValueChanges(const DocIndices& doc
EnumStoreBatchUpdater& updater)
{
using PostingChangeComputer = PostingChangeComputerT<WeightedIndex, PostingMap>;
- EnumStore & enumStore = this->getEnumStore();
- auto comp = enumStore.make_comparator();
EnumIndexMapper mapper;
- PostingMap changePost(PostingChangeComputer::compute(this->getMultiValueMapping(), docIndices, comp, mapper));
+ PostingMap changePost(PostingChangeComputer::compute(this->getMultiValueMapping(), docIndices,
+ this->getEnumStore().make_comparator(), mapper));
this->updatePostings(changePost);
MultiValueNumericEnumAttribute<B, M>::applyValueChanges(docIndices, updater);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp
index 003fb9fa6b7..f1508cfa631 100644
--- a/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multistringattribute.hpp
@@ -120,11 +120,11 @@ StringTemplSearchContext(QueryTermSimpleUP qTerm, const AttrType & toBeSearched)
this->_plsc = static_cast<attribute::IPostingListSearchContext *>(this);
if (this->valid()) {
if (this->isPrefix()) {
- auto comp = enumStore.make_folded_comparator(queryTerm()->getTerm(), true);
+ auto comp = enumStore.make_folded_comparator_prefix(queryTerm()->getTerm());
lookupRange(comp, comp);
} else if (this->isRegex()) {
vespalib::string prefix(vespalib::RegexpUtil::get_prefix(this->queryTerm()->getTerm()));
- auto comp = enumStore.make_folded_comparator(prefix.c_str(), true);
+ auto comp = enumStore.make_folded_comparator_prefix(prefix.c_str());
lookupRange(comp, comp);
} else {
auto comp = enumStore.make_folded_comparator(queryTerm()->getTerm());
diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp
index a464a4d91d6..d5064746cc2 100644
--- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp
@@ -31,7 +31,7 @@ class StringEnumIndexMapper : public EnumIndexMapper
public:
StringEnumIndexMapper(IEnumStoreDictionary & dictionary) : _dictionary(dictionary) { }
IEnumStore::Index map(IEnumStore::Index original) const override;
- virtual bool hasFold() const override { return true; }
+ bool hasFold() const override { return true; }
private:
IEnumStoreDictionary& _dictionary;
};
@@ -44,10 +44,10 @@ applyValueChanges(const DocIndices& docIndices, EnumStoreBatchUpdater &updater)
using PostingChangeComputer = PostingChangeComputerT<WeightedIndex, PostingMap>;
EnumStore &enumStore(this->getEnumStore());
IEnumStoreDictionary& dictionary(enumStore.get_dictionary());
- auto compare = enumStore.make_folded_comparator();
StringEnumIndexMapper mapper(dictionary);
- PostingMap changePost(PostingChangeComputer::compute(this->getMultiValueMapping(), docIndices, compare, mapper));
+ PostingMap changePost(PostingChangeComputer::compute(this->getMultiValueMapping(), docIndices,
+ enumStore.make_folded_comparator(), mapper));
this->updatePostings(changePost);
MultiValueStringAttributeT<B, T>::applyValueChanges(docIndices, updater);
}
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
index 3cf51f43613..5b57b577926 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.cpp
@@ -102,7 +102,7 @@ PostingListAttributeBase<P>::handle_load_posting_lists_and_update_enum_store(enu
template <typename P>
void
PostingListAttributeBase<P>::updatePostings(PostingMap &changePost,
- vespalib::datastore::EntryComparator &cmp)
+ const vespalib::datastore::EntryComparator &cmp)
{
for (auto& elem : changePost) {
EnumIndex idx = elem.first.getEnumIdx();
@@ -145,7 +145,7 @@ PostingListAttributeBase<P>::
clearPostings(attribute::IAttributeVector::EnumHandle eidx,
uint32_t fromLid,
uint32_t toLid,
- vespalib::datastore::EntryComparator &cmp)
+ const vespalib::datastore::EntryComparator &cmp)
{
PostingChange<P> postings;
@@ -213,7 +213,7 @@ handle_load_posting_lists(LoadedVector& loaded)
LoadedValueType prev = value.getValue();
for (size_t i(0), m(loaded.size()); i < m; i++, loaded.next()) {
value = loaded.read();
- if (FoldedComparatorType::equal_helper(prev, value.getValue())) {
+ if (ComparatorType::equal_helper(prev, value.getValue())) {
// for single value attributes loaded[numDocs] is used
// for default value but we don't want to add an
// invalid docId to the posting list.
@@ -267,8 +267,7 @@ void
PostingListAttributeSubBase<P, LoadedVector, LoadedValueType, EnumStoreType>::
updatePostings(PostingMap &changePost)
{
- auto cmp = _es.make_folded_comparator();
- updatePostings(changePost, cmp);
+ updatePostings(changePost, _es.make_folded_comparator());
}
@@ -276,11 +275,9 @@ template <typename P, typename LoadedVector, typename LoadedValueType,
typename EnumStoreType>
void
PostingListAttributeSubBase<P, LoadedVector, LoadedValueType, EnumStoreType>::
-clearPostings(attribute::IAttributeVector::EnumHandle eidx,
- uint32_t fromLid, uint32_t toLid)
+clearPostings(attribute::IAttributeVector::EnumHandle eidx, uint32_t fromLid, uint32_t toLid)
{
- auto cmp = _es.make_folded_comparator();
- clearPostings(eidx, fromLid, toLid, cmp);
+ clearPostings(eidx, fromLid, toLid, _es.make_folded_comparator());
}
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h
index 03348f08486..29c4846edd4 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h
@@ -52,11 +52,11 @@ protected:
IEnumStoreDictionary& _dictionary;
PostingListAttributeBase(AttributeVector &attr, IEnumStore &enumStore);
- virtual ~PostingListAttributeBase();
+ ~PostingListAttributeBase() override;
virtual void updatePostings(PostingMap & changePost) = 0;
- void updatePostings(PostingMap &changePost, vespalib::datastore::EntryComparator &cmp);
+ void updatePostings(PostingMap &changePost, const vespalib::datastore::EntryComparator &cmp);
void clearAllPostings();
void disableFreeLists() { _postingList.disableFreeLists(); }
void disableElemHoldList() { _postingList.disableElemHoldList(); }
@@ -64,10 +64,10 @@ protected:
bool forwardedOnAddDoc(DocId doc, size_t wantSize, size_t wantCapacity);
void clearPostings(attribute::IAttributeVector::EnumHandle eidx, uint32_t fromLid,
- uint32_t toLid, vespalib::datastore::EntryComparator &cmp);
+ uint32_t toLid, const vespalib::datastore::EntryComparator &cmp);
void forwardedShrinkLidSpace(uint32_t newSize) override;
- virtual vespalib::MemoryUsage getMemoryUsage() const override;
+ vespalib::MemoryUsage getMemoryUsage() const override;
public:
const PostingList & getPostingList() const { return _postingList; }
@@ -84,7 +84,7 @@ public:
using EntryRef = vespalib::datastore::EntryRef;
using EnumIndex = IEnumStore::Index;
using EnumStore = EnumStoreType;
- using FoldedComparatorType = typename EnumStore::FoldedComparatorType;
+ using ComparatorType = typename EnumStore::ComparatorType;
using LoadedEnumAttributeVector = attribute::LoadedEnumAttributeVector;
using PostingList = typename Parent::PostingList;
using PostingMap = typename Parent::PostingMap;
@@ -102,7 +102,7 @@ private:
public:
PostingListAttributeSubBase(AttributeVector &attr, EnumStore &enumStore);
- virtual ~PostingListAttributeSubBase();
+ ~PostingListAttributeSubBase() override;
void handle_load_posting_lists(LoadedVector &loaded);
void updatePostings(PostingMap &changePost) override;
diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
index 22e9987aa9e..dac3a1f7453 100644
--- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
+++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.h
@@ -284,11 +284,11 @@ StringPostingSearchContext(QueryTermSimpleUP qTerm, bool useBitVector, const Att
if (this->valid()) {
if (this->isPrefix()) {
- auto comp = _enumStore.make_folded_comparator(this->queryTerm()->getTerm(), true);
+ auto comp = _enumStore.make_folded_comparator_prefix(this->queryTerm()->getTerm());
this->lookupRange(comp, comp);
} else if (this->isRegex()) {
vespalib::string prefix(RegexpUtil::get_prefix(this->queryTerm()->getTerm()));
- auto comp = _enumStore.make_folded_comparator(prefix.c_str(), true);
+ auto comp = _enumStore.make_folded_comparator_prefix(prefix.c_str());
this->lookupRange(comp, comp);
} else {
auto comp = _enumStore.make_folded_comparator(this->queryTerm()->getTerm());
diff --git a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp
index 2bd501eebf2..29c4927efd4 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlenumericpostattribute.hpp
@@ -95,8 +95,7 @@ SingleValueNumericPostingAttribute<B>::applyValueChanges(EnumStoreBatchUpdater&
}
if (change._type == ChangeBase::UPDATE) {
- applyUpdateValueChange(change, enumStore,
- currEnumIndices);
+ applyUpdateValueChange(change, enumStore, currEnumIndices);
} else if (change._type >= ChangeBase::ADD && change._type <= ChangeBase::DIV) {
if (oldIdx.valid()) {
T oldValue = enumStore.get_value(oldIdx);
@@ -107,8 +106,7 @@ SingleValueNumericPostingAttribute<B>::applyValueChanges(EnumStoreBatchUpdater&
}
} else if(change._type == ChangeBase::CLEARDOC) {
this->_defaultValue._doc = change._doc;
- applyUpdateValueChange(this->_defaultValue, enumStore,
- currEnumIndices);
+ applyUpdateValueChange(this->_defaultValue, enumStore, currEnumIndices);
}
}
diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp
index e362ecff6cd..532b83ea03c 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlestringattribute.hpp
@@ -56,11 +56,11 @@ SingleValueStringAttributeT<B>::StringTemplSearchContext::StringTemplSearchConte
this->_plsc = static_cast<attribute::IPostingListSearchContext *>(this);
if (this->valid()) {
if (this->isPrefix()) {
- auto comp = enumStore.make_folded_comparator(queryTerm()->getTerm(), true);
+ auto comp = enumStore.make_folded_comparator_prefix(queryTerm()->getTerm());
lookupRange(comp, comp);
} else if (this->isRegex()) {
vespalib::string prefix(vespalib::RegexpUtil::get_prefix(this->queryTerm()->getTerm()));
- auto comp = enumStore.make_folded_comparator(prefix.c_str(), true);
+ auto comp = enumStore.make_folded_comparator_prefix(prefix.c_str());
lookupRange(comp, comp);
} else {
auto comp = enumStore.make_folded_comparator(queryTerm()->getTerm());
diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h
index 397fad60be3..748d5bc4567 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h
+++ b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.h
@@ -65,11 +65,10 @@ private:
EnumStore & enumStore,
std::map<DocId, EnumIndex> &currEnumIndices);
- void
- makePostingChange(const vespalib::datastore::EntryComparator *cmp,
- IEnumStoreDictionary& dictionary,
- const std::map<DocId, EnumIndex> &currEnumIndices,
- PostingMap &changePost);
+ void makePostingChange(const vespalib::datastore::EntryComparator &cmp,
+ IEnumStoreDictionary& dictionary,
+ const std::map<DocId, EnumIndex> &currEnumIndices,
+ PostingMap &changePost);
void applyValueChanges(EnumStoreBatchUpdater& updater) override;
public:
diff --git a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp
index 402f66d18d1..df6982660f8 100644
--- a/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp
+++ b/searchlib/src/vespa/searchlib/attribute/singlestringpostattribute.hpp
@@ -52,7 +52,7 @@ SingleValueStringPostingAttributeT<B>::applyUpdateValueChange(const Change & c,
template <typename B>
void
SingleValueStringPostingAttributeT<B>::
-makePostingChange(const vespalib::datastore::EntryComparator *cmpa,
+makePostingChange(const vespalib::datastore::EntryComparator &cmpa,
IEnumStoreDictionary& dictionary,
const std::map<DocId, EnumIndex> &currEnumIndices,
PostingMap &changePost)
@@ -64,12 +64,12 @@ makePostingChange(const vespalib::datastore::EntryComparator *cmpa,
// add new posting
auto remapped_new_idx = dictionary.remap_index(newIdx);
- changePost[EnumPostingPair(remapped_new_idx, cmpa)].add(docId, 1);
+ changePost[EnumPostingPair(remapped_new_idx, &cmpa)].add(docId, 1);
// remove old posting
if ( oldIdx.valid()) {
auto remapped_old_idx = dictionary.remap_index(oldIdx);
- changePost[EnumPostingPair(remapped_old_idx, cmpa)].remove(docId);
+ changePost[EnumPostingPair(remapped_old_idx, &cmpa)].remove(docId);
}
}
}
@@ -80,7 +80,6 @@ SingleValueStringPostingAttributeT<B>::applyValueChanges(EnumStoreBatchUpdater&
{
EnumStore & enumStore = this->getEnumStore();
IEnumStoreDictionary& dictionary = enumStore.get_dictionary();
- auto cmp = enumStore.make_folded_comparator();
PostingMap changePost;
// used to make sure several arithmetic operations on the same document in a single commit works
@@ -95,16 +94,14 @@ SingleValueStringPostingAttributeT<B>::applyValueChanges(EnumStoreBatchUpdater&
oldIdx = this->_enumIndices[change._doc];
}
if (change._type == ChangeBase::UPDATE) {
- applyUpdateValueChange(change, enumStore,
- currEnumIndices);
+ applyUpdateValueChange(change, enumStore, currEnumIndices);
} else if (change._type == ChangeBase::CLEARDOC) {
this->_defaultValue._doc = change._doc;
- applyUpdateValueChange(this->_defaultValue, enumStore,
- currEnumIndices);
+ applyUpdateValueChange(this->_defaultValue, enumStore, currEnumIndices);
}
}
- makePostingChange(&cmp, dictionary, currEnumIndices, changePost);
+ makePostingChange(enumStore.make_folded_comparator(), dictionary, currEnumIndices, changePost);
this->updatePostings(changePost);