From 0a7c87eb8b08c0224170eb83bb73bc87f65ecb0f Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 27 Jul 2023 13:58:20 +0300 Subject: Use FlatHashMap in SeqKeyValue. --- tddb/td/db/SeqKeyValue.h | 17 +++++++++++------ tddb/td/db/TsSeqKeyValue.h | 5 ++--- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'tddb') 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 - 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> get_all() const { - return map_; + FlatHashMap get_all() const { + FlatHashMap result; + result.reserve(map_.size()); + for (auto &it : map_) { + result.emplace(it.first, it.second); + } + return result; } private: - std::unordered_map> map_; + FlatHashMap 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 #include namespace td { @@ -69,7 +68,7 @@ class TsSeqKeyValue { return kv_.size(); } - std::unordered_map> get_all() const { + FlatHashMap get_all() const { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.get_all(); } -- cgit v1.2.3