diff options
| author | levlam <levlam@telegram.org> | 2022-08-17 16:52:27 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2022-08-17 16:52:27 +0300 |
| commit | f1c9d69077b007e211b598569e7e3e2df53f796a (patch) | |
| tree | 6088d2d57aa61d2cbadb10795e98a7972ada85c5 /tddb | |
| parent | 5b22effaa637152f677d4ecb008dc3bbc11e732a (diff) | |
Add TsSeqKeyValue::isset.
Diffstat (limited to 'tddb')
| -rw-r--r-- | tddb/td/db/SeqKeyValue.h | 11 | ||||
| -rw-r--r-- | tddb/td/db/TsSeqKeyValue.h | 12 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tddb/td/db/SeqKeyValue.h b/tddb/td/db/SeqKeyValue.h index 3379bb2cc..e785f2140 100644 --- a/tddb/td/db/SeqKeyValue.h +++ b/tddb/td/db/SeqKeyValue.h @@ -32,6 +32,7 @@ class SeqKeyValue { } return next_seq_no(); } + SeqNo erase(const string &key) { auto it = map_.find(key); if (it == map_.end()) { @@ -40,9 +41,11 @@ class SeqKeyValue { map_.erase(it); return next_seq_no(); } + SeqNo seq_no() const { return current_id_ + 1; } + string get(const string &key) const { auto it = map_.find(key); if (it == map_.end()) { @@ -51,6 +54,14 @@ class SeqKeyValue { return it->second; } + bool isset(const string &key) const { + auto it = map_.find(key); + if (it == map_.end()) { + return false; + } + return true; + } + size_t size() const { return map_.size(); } diff --git a/tddb/td/db/TsSeqKeyValue.h b/tddb/td/db/TsSeqKeyValue.h index e26810831..ec962535d 100644 --- a/tddb/td/db/TsSeqKeyValue.h +++ b/tddb/td/db/TsSeqKeyValue.h @@ -33,29 +33,41 @@ class TsSeqKeyValue { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.set(key, value); } + std::pair<SeqNo, RwMutex::WriteLock> set_and_lock(Slice key, Slice value) { auto lock = rw_mutex_.lock_write().move_as_ok(); return std::make_pair(kv_.set(key, value), std::move(lock)); } + SeqNo erase(const string &key) { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.erase(key); } + std::pair<SeqNo, RwMutex::WriteLock> erase_and_lock(const string &key) { auto lock = rw_mutex_.lock_write().move_as_ok(); return std::make_pair(kv_.erase(key), std::move(lock)); } + string get(const string &key) { auto lock = rw_mutex_.lock_read().move_as_ok(); return kv_.get(key); } + + bool isset(const string &key) { + auto lock = rw_mutex_.lock_read().move_as_ok(); + return kv_.isset(key); + } + size_t size() const { return kv_.size(); } + std::unordered_map<string, string> get_all() { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.get_all(); } + // not thread safe method SeqKeyValue &inner() { return kv_; |
