From b25beb13773072c3b143842b45a7c32a1108f347 Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Mon, 15 Apr 2024 14:00:27 -0400 Subject: Updated FSTrie to use const char * instead of std::string Note: this requires the caller to manage the memory of the strings --- include/framework/interface/Record.h | 17 +++++++++++++++++ include/shard/FSTrie.h | 18 +++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/include/framework/interface/Record.h b/include/framework/interface/Record.h index d380f9b..19ccadd 100644 --- a/include/framework/interface/Record.h +++ b/include/framework/interface/Record.h @@ -132,6 +132,23 @@ struct Record { } }; +template +struct Record { + const char* key; + V value; + size_t len; + + inline bool operator<(const Record& other) const { + size_t n = std::min(len, other.len) + 1; + return strncmp(key, other.key, n) < 0; + } + + inline bool operator==(const Record& other) const { + size_t n = std::min(len, other.len) + 1; + return strncmp(key, other.key, n) == 0; + } +}; + template struct WeightedRecord { K key; diff --git a/include/shard/FSTrie.h b/include/shard/FSTrie.h index 95f396f..be678ff 100644 --- a/include/shard/FSTrie.h +++ b/include/shard/FSTrie.h @@ -30,7 +30,7 @@ private: typedef decltype(R::key) K; typedef decltype(R::value) V; - static_assert(std::is_same_v, "FST requires std::string keys."); + static_assert(std::is_same_v, "FST requires const char* keys."); public: FSTrie(BufferView buffer) @@ -42,7 +42,7 @@ public: m_alloc_size = sizeof(Wrapped) * buffer.get_record_count(); size_t cnt = 0; - std::vector keys; + std::vector keys; keys.reserve(buffer.get_record_count()); /* @@ -68,14 +68,10 @@ public: m_data[cnt] = temp_buffer[i]; m_data[cnt].clear_timestamp(); - keys.push_back(m_data[cnt].rec.key); + keys.push_back(std::string(m_data[cnt].rec.key)); cnt++; } - for (size_t i=0; i 0) { m_fst = new fst::Trie(keys); @@ -96,7 +92,7 @@ public: m_data = new Wrapped[attemp_reccnt](); m_alloc_size = attemp_reccnt * sizeof(Wrapped); - std::vector keys; + std::vector keys; keys.reserve(attemp_reccnt); // FIXME: For smaller cursor arrays, it may be more efficient to skip @@ -128,7 +124,7 @@ public: /* skip over records that have been deleted via tagging */ if (!cursor.ptr->is_deleted() && cursor.ptr->rec.key != "") { m_data[m_reccnt] = *cursor.ptr; - keys.push_back(m_data[m_reccnt].rec.key); + keys.push_back(std::string(m_data[m_reccnt].rec.key)); m_reccnt++; } @@ -138,10 +134,6 @@ public: } } - for (size_t i=0; i 0) { m_fst = new fst::Trie(keys); } -- cgit v1.2.3