本文整理汇总了C++中Transaction::add_value方法的典型用法代码示例。如果您正苦于以下问题:C++ Transaction::add_value方法的具体用法?C++ Transaction::add_value怎么用?C++ Transaction::add_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::add_value方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
process_unset(vector<string> cmd_str) {
int val;
int prev_tid, prev_val_tid;
int prev_var_val_cnt, prev_var_val;
Transaction* t = trans_stack.back();
t->clear_value(cmd_str[1]);
// if the variable was modified last in another transaction, add this transaction to the
// var_tid_stack
if ( (!var_tid_stack[cmd_str[1]].empty()) && (t->get_tid() != var_tid_stack[cmd_str[1]].back())) {
prev_tid = var_tid_stack[cmd_str[1]].back();
prev_var_val = trans_stack[prev_tid]->get_value(cmd_str[1]);
if (!val_tid_stack[prev_var_val].empty()) {
prev_val_tid = val_tid_stack[prev_var_val].back();
}
prev_var_val_cnt = trans_stack[prev_val_tid]->get_valMap_value(prev_var_val);
var_tid_stack[cmd_str[1]].push_back(t->get_tid());
// we need a new label -9999 to indicate that the variable was unset
// for process_get aka displaying purposes; use it to update current transaction
t->add_value(cmd_str[1], -9999);
//if value of var is 0, then look for previous tid count and add that to the present tid
if (prev_var_val != -1) {
//the prev var value has changed so add current tid to the val_tid_stack
val_tid_stack[prev_var_val].push_back(t->get_tid());
t->set_valMap_value(prev_var_val, --prev_var_val_cnt);
}
}
}
示例2: atoi
void
process_set(vector<string> cmd_str) {
int val, prev_tid;
int prev_var_tid;
int prev_val_tid, pre_val1, pre_val_count;
int val1, val2;
int size;
int prev_valMap_val;
Transaction* t = trans_stack.back();
val = atoi(cmd_str[2].c_str());
t->add_value(cmd_str[1], val);
if (var_tid_stack.size() == 0) {
var_tid_stack[cmd_str[1]].push_back(t->get_tid());
val_tid_stack[val].push_back(t->get_tid());
}
else {
// if its a never seen before variable
if (var_tid_stack.find(cmd_str[1]) == var_tid_stack.end()) {
var_tid_stack[cmd_str[1]].push_back(t->get_tid());
// if the value added by the new variable was seen before
if (!val_tid_stack[val].empty()) {
prev_tid = val_tid_stack[val].back();
// last count of the value seen before
pre_val_count = trans_stack[prev_tid]->get_valMap_value(val);
// only if its a changed when compared to
if (prev_tid != t->get_tid()) {
t->set_valMap_value(val, pre_val_count + (t->get_valMap_value(val)));
val_tid_stack[val].push_back(t->get_tid());
}
} else {
// if the value was never seen before ... add it to the val_tid_stack
val_tid_stack[val].push_back(t->get_tid());
}
} else {
/* We have seen this variable in other transactions, we need to do two things:
1) add the val_count of present value by one
2) negate the prev_val_count by one.
*/
size = var_tid_stack[cmd_str[1]].size();
//store the last tid that var was changed
int prev_neg_var_tid = var_tid_stack[cmd_str[1]][size - 1];
// ensure to add new tid only if last changed tid is not the present tid
if (var_tid_stack[cmd_str[1]].back() != t->get_tid())
var_tid_stack[cmd_str[1]].push_back(t->get_tid());
if (!val_tid_stack[val].empty()) {
//last tid where val changed
prev_tid = val_tid_stack[val].back();
//last value count the val changed to
pre_val_count = trans_stack[prev_tid]->get_valMap_value(val);
//if previous changed tid is not present tid, add last val count to present val count
if (prev_tid != t->get_tid()) {
t->set_valMap_value(val, pre_val_count + (t->get_valMap_value(val)));
val_tid_stack[val].push_back(t->get_tid());
}
} else {
val_tid_stack[val].push_back(t->get_tid());
}
//Now negate old value
//since we push var in var_tid_stack, obtain the second last push.
// and use it to obtain the val it previously held in that tid
if (prev_neg_var_tid != t->get_tid()) {
// we get value of var from prev_tid
val1 = trans_stack[prev_neg_var_tid]->get_value(cmd_str[1]);
if (!val_tid_stack[val1].empty()) {
//obtain the count of var val1
val2 = trans_stack[prev_neg_var_tid]->get_valMap_value(val1);
//decrement it
t->set_valMap_value(val1, val2-1);
if (val_tid_stack[val1].back() != t->get_tid()) {
val_tid_stack[val1].push_back(t->get_tid());
}
}
}
}
}
}