Пример #1
0
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
0
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());					
					}
				}
			}
			
		}
	}

}