diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-09 12:50:25 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-09 12:52:29 +0000 |
commit | 979ff012778f100fe8f125d6c1535ef28c059584 (patch) | |
tree | c93d3c3d42c2c2cd651c611ed115ae0245e22e98 /searchlib | |
parent | 4f826fdf0353af5363e0464c02976787939973a0 (diff) |
Convert comparator from being a simple comparator to using an explicit less method.
Diffstat (limited to 'searchlib')
9 files changed, 43 insertions, 43 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 4e1e1c6d792..ccd30c72b0e 100644 --- a/searchlib/src/tests/attribute/enum_comparator/enum_comparator_test.cpp +++ b/searchlib/src/tests/attribute/enum_comparator/enum_comparator_test.cpp @@ -44,12 +44,12 @@ Test::requireThatNumericComparatorIsWorking() EnumIndex e1 = es.insert(10); EnumIndex e2 = es.insert(30); auto cmp1 = es.make_comparator(); - EXPECT_TRUE(cmp1(e1, e2)); - EXPECT_TRUE(!cmp1(e2, e1)); - EXPECT_TRUE(!cmp1(e1, e1)); + EXPECT_TRUE(cmp1.less(e1, e2)); + EXPECT_TRUE(!cmp1.less(e2, e1)); + EXPECT_TRUE(!cmp1.less(e1, e1)); auto cmp2 = es.make_comparator(20); - EXPECT_TRUE(cmp2(EnumIndex(), e2)); - EXPECT_TRUE(!cmp2(e2, EnumIndex())); + EXPECT_TRUE(cmp2.less(EnumIndex(), e2)); + EXPECT_TRUE(!cmp2.less(e2, EnumIndex())); } void @@ -60,15 +60,15 @@ Test::requireThatFloatComparatorIsWorking() EnumIndex e2 = es.insert(30.5); EnumIndex e3 = es.insert(std::numeric_limits<float>::quiet_NaN()); auto cmp1 = es.make_comparator(); - EXPECT_TRUE(cmp1(e1, e2)); - EXPECT_TRUE(!cmp1(e2, e1)); - EXPECT_TRUE(!cmp1(e1, e1)); - EXPECT_TRUE(cmp1(e3, e1)); // nan - EXPECT_TRUE(!cmp1(e1, e3)); // nan - EXPECT_TRUE(!cmp1(e3, e3)); // nan + EXPECT_TRUE(cmp1.less(e1, e2)); + EXPECT_TRUE(!cmp1.less(e2, e1)); + EXPECT_TRUE(!cmp1.less(e1, e1)); + EXPECT_TRUE(cmp1.less(e3, e1)); // nan + EXPECT_TRUE(!cmp1.less(e1, e3)); // nan + EXPECT_TRUE(!cmp1.less(e3, e3)); // nan auto cmp2 = es.make_comparator(20.5); - EXPECT_TRUE(cmp2(EnumIndex(), e2)); - EXPECT_TRUE(!cmp2(e2, EnumIndex())); + EXPECT_TRUE(cmp2.less(EnumIndex(), e2)); + EXPECT_TRUE(!cmp2.less(e2, EnumIndex())); } void @@ -79,14 +79,14 @@ Test::requireThatStringComparatorIsWorking() EnumIndex e2 = es.insert("aa"); EnumIndex e3 = es.insert("aB"); auto cmp1 = es.make_comparator(); - EXPECT_TRUE(cmp1(e1, e2)); // similar folded, fallback to regular - EXPECT_TRUE(!cmp1(e2, e1)); - EXPECT_TRUE(!cmp1(e1, e1)); - EXPECT_TRUE(cmp1(e2, e3)); // folded compare + EXPECT_TRUE(cmp1.less(e1, e2)); // similar folded, fallback to regular + EXPECT_TRUE(!cmp1.less(e2, e1)); + EXPECT_TRUE(!cmp1.less(e1, e1)); + EXPECT_TRUE(cmp1.less(e2, e3)); // folded compare EXPECT_TRUE(strcmp("aa", "aB") > 0); // regular auto cmp2 = es.make_comparator("AB"); - EXPECT_TRUE(cmp2(EnumIndex(), e3)); - EXPECT_TRUE(!cmp2(e3, EnumIndex())); + EXPECT_TRUE(cmp2.less(EnumIndex(), e3)); + EXPECT_TRUE(!cmp2.less(e3, EnumIndex())); } void @@ -124,16 +124,16 @@ Test::requireThatFoldedComparatorIsWorking() EnumIndex e3 = es.insert("aB"); EnumIndex e4 = es.insert("Folded"); auto cmp1 = es.make_folded_comparator(); - EXPECT_TRUE(!cmp1(e1, e2)); // similar folded - EXPECT_TRUE(!cmp1(e2, e1)); // similar folded - EXPECT_TRUE(cmp1(e2, e3)); // folded compare - EXPECT_TRUE(!cmp1(e3, e2)); // folded compare + EXPECT_TRUE(!cmp1.less(e1, e2)); // similar folded + EXPECT_TRUE(!cmp1.less(e2, e1)); // similar folded + EXPECT_TRUE(cmp1.less(e2, e3)); // folded compare + EXPECT_TRUE(!cmp1.less(e3, e2)); // folded compare auto cmp2 = es.make_folded_comparator("fol", false); auto cmp3 = es.make_folded_comparator("fol", true); - EXPECT_TRUE(cmp2(EnumIndex(), e4)); - EXPECT_TRUE(!cmp2(e4, EnumIndex())); - EXPECT_TRUE(!cmp3(EnumIndex(), e4)); // similar when prefix - EXPECT_TRUE(!cmp3(e4, EnumIndex())); // similar when prefix + EXPECT_TRUE(cmp2.less(EnumIndex(), e4)); + EXPECT_TRUE(!cmp2.less(e4, EnumIndex())); + EXPECT_TRUE(!cmp3.less(EnumIndex(), e4)); // similar when prefix + EXPECT_TRUE(!cmp3.less(e4, EnumIndex())); // similar when prefix } int diff --git a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp index 19d30317c7b..ed16dc2d8d8 100644 --- a/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp +++ b/searchlib/src/vespa/searchlib/attribute/enum_store_dictionary.cpp @@ -122,7 +122,7 @@ EnumStoreDictionary<DictionaryT>::find_matching_enums(const vespalib::datastore: { std::vector<IEnumStore::EnumHandle> result; auto itr = this->_dict.getFrozenView().find(Index(), cmp); - while (itr.valid() && !cmp(Index(), itr.getKey())) { + while (itr.valid() && !cmp.less(Index(), itr.getKey())) { result.push_back(itr.getKey().ref()); ++itr; } @@ -169,7 +169,7 @@ UniqueStoreAddResult EnumStoreFoldedDictionary::add(const EntryComparator& comp, std::function<EntryRef(void)> insertEntry) { auto it = _dict.lowerBound(EntryRef(), comp); - if (it.valid() && !comp(EntryRef(), it.getKey())) { + if (it.valid() && !comp.less(EntryRef(), it.getKey())) { // Entry already exists return UniqueStoreAddResult(it.getKey(), false); } @@ -177,7 +177,7 @@ EnumStoreFoldedDictionary::add(const EntryComparator& comp, std::function<EntryR _dict.insert(it, newRef, EntryRef().ref()); // Maybe move posting list reference from next entry ++it; - if (it.valid() && EntryRef(it.getData()).valid() && !(*_folded_compare)(newRef, it.getKey())) { + if (it.valid() && EntryRef(it.getData()).valid() && !_folded_compare->less(newRef, it.getKey())) { EntryRef posting_list_ref(it.getData()); _dict.thaw(it); it.writeData(EntryRef().ref()); @@ -198,7 +198,7 @@ EnumStoreFoldedDictionary::remove(const EntryComparator& comp, EntryRef ref) _dict.remove(it); // Maybe copy posting list reference to next entry if (posting_list_ref.valid()) { - if (it.valid() && !EntryRef(it.getData()).valid() && !(*_folded_compare)(ref, it.getKey())) { + if (it.valid() && !EntryRef(it.getData()).valid() && !_folded_compare->less(ref, it.getKey())) { this->_dict.thaw(it); it.writeData(posting_list_ref.ref()); } else { diff --git a/searchlib/src/vespa/searchlib/attribute/enumcomparator.h b/searchlib/src/vespa/searchlib/attribute/enumcomparator.h index aaf47987a5d..e0a5b456fd5 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumcomparator.h +++ b/searchlib/src/vespa/searchlib/attribute/enumcomparator.h @@ -51,7 +51,7 @@ public: return compare(lhs, rhs) == 0; } - bool operator() (const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override { + bool less(const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override { return compare(get(lhs), get(rhs)) < 0; } }; @@ -95,7 +95,7 @@ public: return compare_folded(lhs, rhs) == 0; } - bool operator() (const vespalib::datastore::EntryRef lhs, const vespalib::datastore::EntryRef rhs) const override { + 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; } diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.cpp b/searchlib/src/vespa/searchlib/attribute/enumstore.cpp index 0ad8a7d7c5b..ecd55138df1 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumstore.cpp +++ b/searchlib/src/vespa/searchlib/attribute/enumstore.cpp @@ -35,7 +35,7 @@ EnumStoreT<const char*>::load_unique_value(const void* src, if (prev_idx.valid()) { auto cmp = make_comparator(value); - assert(cmp(prev_idx, Index())); + assert(cmp.less(prev_idx, Index())); } return sz; } diff --git a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp index 54c756ee437..c1098f079e6 100644 --- a/searchlib/src/vespa/searchlib/attribute/enumstore.hpp +++ b/searchlib/src/vespa/searchlib/attribute/enumstore.hpp @@ -66,7 +66,7 @@ EnumStoreT<EntryT>::load_unique_value(const void* src, size_t available, Index& if (prev_idx.valid()) { auto cmp = make_comparator(*value); - assert(cmp(prev_idx, Index())); + assert(cmp.less(prev_idx, Index())); } return sizeof(EntryType); } @@ -159,8 +159,8 @@ bool EnumStoreT<EntryT>::is_folded_change(Index idx1, Index idx2) const { auto cmp = make_folded_comparator(); - assert(!cmp(idx2, idx1)); - return cmp(idx1, idx2); + assert(!cmp.less(idx2, idx1)); + return cmp.less(idx1, idx2); } template <typename EntryT> diff --git a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp index 1fd1cd09bea..ed19e6ae0ba 100644 --- a/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multinumericpostattribute.hpp @@ -103,7 +103,7 @@ MultiValueNumericPostingAttribute<B, M>::DocumentWeightAttributeAdapter::lookup( auto comp = self._enumStore.make_comparator(int_term); dictItr.lower_bound(dictionary_snapshot, EnumIndex(), comp); - if (dictItr.valid() && !comp(EnumIndex(), dictItr.getKey())) { + if (dictItr.valid() && !comp.less(EnumIndex(), dictItr.getKey())) { vespalib::datastore::EntryRef pidx(dictItr.getData()); if (pidx.valid()) { const PostingList &plist = self.getPostingList(); diff --git a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp index 25d7858ea81..f97a4e281a8 100644 --- a/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp +++ b/searchlib/src/vespa/searchlib/attribute/multistringpostattribute.hpp @@ -115,7 +115,7 @@ MultiValueStringPostingAttributeT<B, T>::DocumentWeightAttributeAdapter::lookup( auto comp = self._enumStore.make_folded_comparator(term.c_str()); dictItr.lower_bound(dictionary_snapshot, enumstore::Index(), comp); - if (dictItr.valid() && !comp(enumstore::Index(), dictItr.getKey())) { + if (dictItr.valid() && !comp.less(enumstore::Index(), dictItr.getKey())) { vespalib::datastore::EntryRef pidx(dictItr.getData()); if (pidx.valid()) { const PostingList &plist = self.getPostingList(); @@ -134,7 +134,7 @@ MultiValueStringPostingAttributeT<B, T>::DocumentWeightAttributeAdapter::collect 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(enum_idx, dictItr.getKey())) { + while (dictItr.valid() && !comp.less(enum_idx, dictItr.getKey())) { callback(dictItr.getKey()); ++dictItr; } diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h index 5f2eb02ecd2..eab8d1576fd 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h +++ b/searchlib/src/vespa/searchlib/attribute/postinglistattribute.h @@ -28,7 +28,7 @@ public: _cmp(cmp) { } - bool operator<(const EnumPostingPair &rhs) const { return (*_cmp)(_idx, rhs._idx); } + bool operator<(const EnumPostingPair &rhs) const { return _cmp->less(_idx, rhs._idx); } IEnumStore::Index getEnumIdx() const { return _idx; } }; diff --git a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp index 972baa267ce..1c9b8dbf7b2 100644 --- a/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp +++ b/searchlib/src/vespa/searchlib/attribute/postinglistsearchcontext.cpp @@ -46,7 +46,7 @@ PostingListSearchContext::lookupTerm(const vespalib::datastore::EntryComparator { _lowerDictItr.lower_bound(_frozenDictionary.getRoot(), EnumIndex(), comp); _upperDictItr = _lowerDictItr; - if (_upperDictItr.valid() && !comp(EnumIndex(), _upperDictItr.getKey())) { + if (_upperDictItr.valid() && !comp.less(EnumIndex(), _upperDictItr.getKey())) { ++_upperDictItr; _uniqueValues = 1u; } @@ -59,7 +59,7 @@ PostingListSearchContext::lookupRange(const vespalib::datastore::EntryComparator { _lowerDictItr.lower_bound(_frozenDictionary.getRoot(), EnumIndex(), low); _upperDictItr = _lowerDictItr; - if (_upperDictItr.valid() && !high(EnumIndex(), _upperDictItr.getKey())) { + if (_upperDictItr.valid() && !high.less(EnumIndex(), _upperDictItr.getKey())) { _upperDictItr.seekPast(EnumIndex(), high); } _uniqueValues = _upperDictItr - _lowerDictItr; |