diff options
Diffstat (limited to 'tddb')
| -rw-r--r-- | tddb/td/db/SeqKeyValue.h | 17 | ||||
| -rw-r--r-- | tddb/td/db/TsSeqKeyValue.h | 5 |
2 files changed, 13 insertions, 9 deletions
diff --git a/tddb/td/db/SeqKeyValue.h b/tddb/td/db/SeqKeyValue.h index 9870ac939..b12975cfb 100644 --- a/tddb/td/db/SeqKeyValue.h +++ b/tddb/td/db/SeqKeyValue.h @@ -6,11 +6,9 @@ // #pragma once -#include "td/utils/HashTableUtils.h" +#include "td/utils/FlatHashMap.h" #include "td/utils/Slice.h" -#include <unordered_map> - namespace td { class SeqKeyValue { @@ -24,6 +22,7 @@ class SeqKeyValue { ~SeqKeyValue() = default; SeqNo set(Slice key, Slice value) { + CHECK(!key.empty()); auto it_ok = map_.emplace(key.str(), value.str()); if (!it_ok.second) { if (it_ok.first->second == value) { @@ -84,13 +83,19 @@ class SeqKeyValue { return map_.size(); } - std::unordered_map<string, string, Hash<string>> get_all() const { - return map_; + FlatHashMap<string, string> get_all() const { + FlatHashMap<string, string> result; + result.reserve(map_.size()); + for (auto &it : map_) { + result.emplace(it.first, it.second); + } + return result; } private: - std::unordered_map<string, string, Hash<string>> map_; + FlatHashMap<string, string> map_; SeqNo current_id_ = 0; + SeqNo next_seq_no() { return ++current_id_; } diff --git a/tddb/td/db/TsSeqKeyValue.h b/tddb/td/db/TsSeqKeyValue.h index ebb413289..ec56b9738 100644 --- a/tddb/td/db/TsSeqKeyValue.h +++ b/tddb/td/db/TsSeqKeyValue.h @@ -8,11 +8,10 @@ #include "td/db/SeqKeyValue.h" -#include "td/utils/HashTableUtils.h" +#include "td/utils/FlatHashMap.h" #include "td/utils/port/RwMutex.h" #include "td/utils/Slice.h" -#include <unordered_map> #include <utility> namespace td { @@ -69,7 +68,7 @@ class TsSeqKeyValue { return kv_.size(); } - std::unordered_map<string, string, Hash<string>> get_all() const { + FlatHashMap<string, string> get_all() const { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.get_all(); } |
