Skip to content

Commit

Permalink
Add TsSeqKeyValue::isset.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed Aug 17, 2022
1 parent 5b22eff commit f1c9d69
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tddb/td/db/SeqKeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class SeqKeyValue {
}
return next_seq_no();
}

SeqNo erase(const string &key) {
auto it = map_.find(key);
if (it == map_.end()) {
Expand All @@ -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()) {
Expand All @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions tddb/td/db/TsSeqKeyValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit f1c9d69

Please sign in to comment.