Skip to content

Commit

Permalink
use the unordered_set instead of unordered_map
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiaoshuai123 committed Nov 27, 2023
1 parent 5d6d445 commit 6b17abf
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ thread-pool-size : 12
slow-cmd-thread-pool-size : 4

# Slow cmd list e.g. hgetall,mset
slow-cmd-list : ""
slow-cmd-list :

# The number of sync-thread for data replication from master, those are the threads work on slave nodes
# and are used to execute commands sent from master node when replicating.
Expand Down
6 changes: 3 additions & 3 deletions include/pika_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ class PikaConf : public pstd::BaseConf {
// Slow Commands configuration
const std::string GetSlowCmd() {
std::shared_lock l(rwlock_);
return pstd::Map2String(slow_cmd_set_, ',');
return pstd::Set2String(slow_cmd_set_, ',');
}

bool is_slow_cmd(const std::string &cmd) {
Expand Down Expand Up @@ -612,7 +612,7 @@ class PikaConf : public pstd::BaseConf {
std::string lower_value = value;
pstd::StringToLower(lower_value);
TryPushDiffCommands("slow-cmd-list", lower_value);
pstd::StringSplit2Map(lower_value, ',', slow_cmd_set_);
pstd::StringSplit2Set(lower_value, ',', slow_cmd_set_);
}

pstd::Status DBSlotsSanityCheck(const std::string& db_name, const std::set<uint32_t>& slot_ids,
Expand All @@ -637,7 +637,7 @@ class PikaConf : public pstd::BaseConf {
int thread_num_ = 0;
int thread_pool_size_ = 0;
int slow_cmd_thread_pool_size_ = 0;
std::unordered_map<std::string, std::string> slow_cmd_set_;
std::unordered_set<std::string> slow_cmd_set_;
int sync_thread_num_ = 0;
std::string log_path_;
std::string log_level_;
Expand Down
2 changes: 1 addition & 1 deletion src/pika_conf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ int PikaConf::ConfigRewrite() {
SetConfInt("sync-window-size", sync_window_size_.load());
SetConfInt("consensus-level", consensus_level_.load());
SetConfInt("replication-num", replication_num_.load());
SetConfStr("slow-cmd-list", pstd::Map2String(slow_cmd_set_, ','));
SetConfStr("slow-cmd-list", pstd::Set2String(slow_cmd_set_, ','));
// options for storage engine
SetConfInt("max-cache-files", max_cache_files_);
SetConfInt("max-background-compactions", max_background_compactions_);
Expand Down
6 changes: 3 additions & 3 deletions src/pstd/include/pstd_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>

namespace pstd {

Expand All @@ -51,8 +51,8 @@ int string2int(const char* s, size_t slen, unsigned long* lval);
int d2string(char* buf, size_t len, double value);
int string2d(const char* s, size_t slen, double* dval);
std::vector<std::string>& StringSplit(const std::string& s, char delim, std::vector<std::string>& elems);
void StringSplit2Map(const std::string&s, char delim, std::unordered_map<std::string, std::string>& elems);
std::string Map2String(const std::unordered_map<std::string, std::string>& elems, char delim);
void StringSplit2Set(const std::string&s, char delim, std::unordered_set<std::string>& elems);
std::string Set2String(const std::unordered_set<std::string>& elems, char delim);
std::string StringConcat(const std::vector<std::string>& elems, char delim);
std::string& StringToLower(std::string& ori);
std::string& StringToUpper(std::string& ori);
Expand Down
8 changes: 4 additions & 4 deletions src/pstd/src/pstd_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -597,22 +597,22 @@ std::vector<std::string>& StringSplit(const std::string& s, char delim, std::vec
return elems;
}

void StringSplit2Map(const std::string& s, char delim, std::unordered_map<std::string, std::string>& elems) {
void StringSplit2Set(const std::string& s, char delim, std::unordered_set<std::string>& elems) {
elems.clear();
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
item = pstd::StringTrim(item);
if (!item.empty()) {
elems[item] = "";
elems.emplace(item);
}
}
}

std::string Map2String(const std::unordered_map<std::string, std::string>& elems, char delim) {
std::string Set2String(const std::unordered_set<std::string>& elems, char delim) {
std::string value;
for (const auto &e : elems) {
value.append(e.first);
value.append(e);
value.append(1, delim);
}
if (!value.empty()) {
Expand Down

0 comments on commit 6b17abf

Please sign in to comment.