Skip to content

Commit

Permalink
add cmp case
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix20162016 committed Jun 12, 2024
1 parent 421d717 commit c228b27
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
47 changes: 47 additions & 0 deletions example/mpc_cmp_task_conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"task_type": "ACTOR_TASK",
"task_name": "mpc_cmp",
"task_lang": "proto",
"task_code": {
"code_file_path": "",
"code": "arithmetic"
},
"params": {
"ResFileName": {
"type": "STRING",
"value": "data/result/mpc_cmp_result.csv"
},
"Expr": {
"type": "STRING",
"value": "CMP(A, B)"
},
"RevealToParties": {
"type": "STRING",
"value": "PARTY2"
},
"Col_And_Owner": {
"type": "STRING",
"value": "A-PARTY0;B-PARTY1"
},
"Col_And_Dtype": {
"descrtion": "0: int64_t, 1: double",
"type": "STRING",
"value": "A-0;B-0"
},
"Accuracy": {
"type": "STRING",
"value": "D16"
}
},
"party_datasets": {
"PARTY0": {
"Data_File": "mpc_arithmetic_0"
},
"PARTY1": {
"Data_File": "mpc_arithmetic_1"
},
"PARTY2": {
"Data_File": "FAKE_DATA_PARTY_2"
}
}
}
3 changes: 3 additions & 0 deletions src/primihub/algorithm/arithmetic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ int ArithmeticExecutor<Dbit>::loadParams(primihub::rpc::Task &task) {

// col_and_owner
std::string col_and_owner = param_map["Col_And_Owner"].value_string();
TrimAll(col_and_owner);
std::vector<std::string> tmp1, tmp2, tmp3;
str_split(col_and_owner, &tmp1, ';');
for (auto itr = tmp1.begin(); itr != tmp1.end(); itr++) {
Expand All @@ -113,6 +114,7 @@ int ArithmeticExecutor<Dbit>::loadParams(primihub::rpc::Task &task) {
// LOG(INFO) << col_and_owner;

std::string col_and_dtype = param_map["Col_And_Dtype"].value_string();
TrimAll(col_and_dtype);
str_split(col_and_dtype, &tmp2, ';');
for (auto itr = tmp2.begin(); itr != tmp2.end(); itr++) {
int pos = itr->find('-');
Expand All @@ -124,6 +126,7 @@ int ArithmeticExecutor<Dbit>::loadParams(primihub::rpc::Task &task) {
// LOG(INFO) << col_and_dtype;

expr_ = param_map["Expr"].value_string();
TrimAll(expr_);
int comma_index = expr_.find(",");
cmp_col1 = expr_.substr(4, comma_index - 4);
cmp_col2 = expr_.substr(comma_index + 1, expr_.length() - comma_index - 2);
Expand Down
24 changes: 24 additions & 0 deletions src/primihub/util/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,28 @@ std::string buf_to_hex_string(const uint8_t* pdata, size_t size) {
return ss.str();
}

void TrimLeft(std::string& str) {
if (str.empty()) {
return;
}
str.erase(str.begin(),
std::find_if(str.begin(), str.end(), [](unsigned char ch) {
return !std::isspace(ch);}));
}

void TrimRight(std::string& str) {
if (str.empty()) {
return;
}
str.erase(std::find_if(str.rbegin(), str.rend(), [](unsigned char ch) {
return !std::isspace(ch);}).base(), str.end());
}

void TrimAll(std::string& str) {
if (str.empty()) {
return;
}
str.erase(remove_if(str.begin(), str.end(), [](unsigned char ch) {
return std::isspace(ch);}), str.end());
}
} // namespace primihub
3 changes: 3 additions & 0 deletions src/primihub/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ retcode pbNode2Node(const primihub::rpc::Node& pb_node, Node* node);
retcode node2PbNode(const Node& node, rpc::Node* pb_node);
retcode parseToNode(const std::string& node_info, Node* node);
retcode parseTopbNode(const std::string& node_info, rpc::Node* node);
void TrimLeft(std::string& str);
void TrimRight(std::string& str);
void TrimAll(std::string& str);

class SCopedTimer {
public:
Expand Down

0 comments on commit c228b27

Please sign in to comment.