summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2021-02-02 14:05:39 +0000
committerHåvard Pettersen <havardpe@oath.com>2021-02-02 15:04:47 +0000
commitb6472df72687995369aeef76f46a2fc137f97909 (patch)
treea570e7679afbc69c95606a5932e67e7cea954889 /vespalib
parent4b3b7543f0f8acf3f72d25d76e36d63841de278a (diff)
added some optimizations for single-dimension sparse matching
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp11
-rw-r--r--vespalib/src/vespa/vespalib/util/string_id.h1
2 files changed, 9 insertions, 3 deletions
diff --git a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp
index 4c3c32c2326..97c767a17ed 100644
--- a/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp
+++ b/vespalib/src/tests/shared_string_repo/shared_string_repo_test.cpp
@@ -361,6 +361,8 @@ TEST("require that basic handle usage works") {
TEST_DO(verify_not_eq(empty, bar));
TEST_DO(verify_not_eq(foo, bar));
+ EXPECT_EQUAL(empty.id().hash(), 0u);
+ EXPECT_EQUAL(empty.id().value(), 0u);
EXPECT_TRUE(empty.id() == string_id());
EXPECT_TRUE(empty2.id() == string_id());
EXPECT_EQUAL(empty.as_string(), vespalib::string(""));
@@ -415,9 +417,11 @@ TEST("require that handle can be self-assigned") {
//-----------------------------------------------------------------------------
-void verify_direct(const vespalib::string &str) {
+void verify_direct(const vespalib::string &str, size_t value) {
size_t before = SharedStringRepo::stats().active_entries;
Handle handle(str);
+ EXPECT_EQUAL(handle.id().hash(), value + 1);
+ EXPECT_EQUAL(handle.id().value(), value + 1);
EXPECT_EQUAL(SharedStringRepo::stats().active_entries, before);
EXPECT_EQUAL(handle.as_string(), str);
}
@@ -425,14 +429,15 @@ void verify_direct(const vespalib::string &str) {
void verify_not_direct(const vespalib::string &str) {
size_t before = SharedStringRepo::stats().active_entries;
Handle handle(str);
+ EXPECT_EQUAL(handle.id().hash(), handle.id().value());
EXPECT_EQUAL(SharedStringRepo::stats().active_entries, before + 1);
EXPECT_EQUAL(handle.as_string(), str);
}
TEST("require that direct handles work as expected") {
- TEST_DO(verify_direct(""));
+ TEST_DO(verify_direct("", -1));
for (size_t i = 0; i < 100000; ++i) {
- verify_direct(fmt("%zu", i));
+ verify_direct(fmt("%zu", i), i);
}
TEST_DO(verify_not_direct(" "));
TEST_DO(verify_not_direct(" 5"));
diff --git a/vespalib/src/vespa/vespalib/util/string_id.h b/vespalib/src/vespa/vespalib/util/string_id.h
index 3e608c9d339..371caf8bf95 100644
--- a/vespalib/src/vespa/vespalib/util/string_id.h
+++ b/vespalib/src/vespa/vespalib/util/string_id.h
@@ -31,6 +31,7 @@ public:
constexpr string_id &operator=(const string_id &) noexcept = default;
constexpr string_id &operator=(string_id &&) noexcept = default;
constexpr uint32_t hash() const noexcept { return _id; }
+ constexpr uint32_t value() const noexcept { return _id; }
// NB: not lexical sorting order, but can be used in maps
constexpr bool operator<(const string_id &rhs) const noexcept { return (_id < rhs._id); }
constexpr bool operator==(const string_id &rhs) const noexcept { return (_id == rhs._id); }