summaryrefslogtreecommitdiffstats
path: root/vespalib/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-03-09 15:42:55 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-03-09 15:42:55 +0000
commit6767eb4c65a82202f6b642751e8050836dbaf5d0 (patch)
tree7ebd638c8619ed6f8ed5b7ee8c70255cef17caaf /vespalib/src
parent7f81c030ecb230a75a21e02e78fa6bb9290f4a69 (diff)
Add simple equal to Comparator interface.
Diffstat (limited to 'vespalib/src')
-rw-r--r--vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp3
-rw-r--r--vespalib/src/vespa/vespalib/datastore/entry_comparator.h1
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h17
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h5
4 files changed, 26 insertions, 0 deletions
diff --git a/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp b/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp
index fc5709072b9..08b80917f45 100644
--- a/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp
+++ b/vespalib/src/tests/datastore/unique_store_dictionary/unique_store_dictionary_test.cpp
@@ -28,6 +28,9 @@ public:
bool less(const EntryRef lhs, const EntryRef rhs) const override {
return resolve(lhs).ref() < resolve(rhs).ref();
}
+ bool equal(const EntryRef lhs, const EntryRef rhs) const override {
+ return resolve(lhs).ref() == resolve(rhs).ref();
+ }
};
struct DictionaryReadTest : public ::testing::Test {
diff --git a/vespalib/src/vespa/vespalib/datastore/entry_comparator.h b/vespalib/src/vespa/vespalib/datastore/entry_comparator.h
index 027b27bec08..41ecf229d8f 100644
--- a/vespalib/src/vespa/vespalib/datastore/entry_comparator.h
+++ b/vespalib/src/vespa/vespalib/datastore/entry_comparator.h
@@ -20,6 +20,7 @@ public:
* Returns true if the value represented by lhs ref is less than the value represented by rhs ref.
*/
virtual bool less(const EntryRef lhs, const EntryRef rhs) const = 0;
+ virtual bool equal(const EntryRef lhs, const EntryRef rhs) const = 0;
};
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h
index c99345252d3..630c53e7b08 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_comparator.h
@@ -18,6 +18,9 @@ public:
static bool less(const EntryT& lhs, const EntryT& rhs) {
return lhs < rhs;
}
+ static bool equal(const EntryT& lhs, const EntryT& rhs) {
+ return lhs == rhs;
+ }
};
/**
@@ -37,6 +40,15 @@ public:
return (lhs < rhs);
}
}
+ static bool equal(EntryT lhs, const EntryT rhs) {
+ if (std::isnan(lhs)) {
+ return std::isnan(rhs);
+ } else if (std::isnan(rhs)) {
+ return false;
+ } else {
+ return (lhs == rhs);
+ }
+ }
};
/**
@@ -98,6 +110,11 @@ public:
const EntryType &rhsValue = get(rhs);
return UniqueStoreComparatorHelper<EntryT>::less(lhsValue, rhsValue);
}
+ bool equal(const EntryRef lhs, const EntryRef rhs) const override {
+ const EntryType &lhsValue = get(lhs);
+ const EntryType &rhsValue = get(rhs);
+ return UniqueStoreComparatorHelper<EntryT>::equal(lhsValue, rhsValue);
+ }
};
}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h
index a3bd1267049..0be0e3e8d9d 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_comparator.h
@@ -49,6 +49,11 @@ public:
const char *rhs_value = get(rhs);
return (strcmp(lhs_value, rhs_value) < 0);
}
+ bool equal(const EntryRef lhs, const EntryRef rhs) const override {
+ const char *lhs_value = get(lhs);
+ const char *rhs_value = get(rhs);
+ return (strcmp(lhs_value, rhs_value) == 0);
+ }
};
}