diff options
| author | Douglas Rumbaugh <dbr4@psu.edu> | 2024-04-15 14:00:27 -0400 |
|---|---|---|
| committer | Douglas Rumbaugh <dbr4@psu.edu> | 2024-04-15 14:00:27 -0400 |
| commit | b25beb13773072c3b143842b45a7c32a1108f347 (patch) | |
| tree | 97f490a4b8e527e6281df2cb1ee8f1fab84f1f8d /include | |
| parent | 2c69253f382cd0c6d41db57c45119c33c315bb9c (diff) | |
| download | dynamic-extension-b25beb13773072c3b143842b45a7c32a1108f347.tar.gz | |
Updated FSTrie to use const char * instead of std::string
Note: this requires the caller to manage the memory of the strings
Diffstat (limited to 'include')
| -rw-r--r-- | include/framework/interface/Record.h | 17 | ||||
| -rw-r--r-- | include/shard/FSTrie.h | 18 |
2 files changed, 22 insertions, 13 deletions
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<typename V> +struct Record<const char*, V> { + 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 <typename K, typename V, typename W> 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<K, std::string>, "FST requires std::string keys."); + static_assert(std::is_same_v<K, const char*>, "FST requires const char* keys."); public: FSTrie(BufferView<R> buffer) @@ -42,7 +42,7 @@ public: m_alloc_size = sizeof(Wrapped<R>) * buffer.get_record_count(); size_t cnt = 0; - std::vector<K> keys; + std::vector<std::string> 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<keys.size() - 1; i++) { - assert(keys[i] <= keys[i+1]); - } - m_reccnt = cnt; if (m_reccnt > 0) { m_fst = new fst::Trie(keys); @@ -96,7 +92,7 @@ public: m_data = new Wrapped<R>[attemp_reccnt](); m_alloc_size = attemp_reccnt * sizeof(Wrapped<R>); - std::vector<K> keys; + std::vector<std::string> 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<keys.size() - 1; i++) { - assert(keys[i] <= keys[i+1]); - } - if (m_reccnt > 0) { m_fst = new fst::Trie(keys); } |