add generation algorithm to generate operations

This commit is contained in:
2021-01-10 15:06:52 +01:00
parent 47936e23f9
commit e2d1e726f0

View File

@@ -18,58 +18,30 @@ using namespace std::chrono;
#define OP_COUNT 100000 #define OP_COUNT 100000
#define THREADS 4 #define THREADS 4
enum methodname {push, pop, size, noop}; std::vector<operation> generate_operations_uniform(){
typedef struct _operation{ operation default_operation = create_operation(methodname::push, 0);
methodname method; std::vector<operation> operations(OP_COUNT, default_operation);
int input;
} operation;
void do_operation(operation* op, Stack* set) { int stack_size = 0;
switch (op->method) { for (auto op = operations.begin(); op != operations.end(); op++) {
case methodname::push: switch (rand() % 3) {
break; case 0:
case methodname::pop: if (stack_size > 0) {
break; op->method = methodname::pop;
case methodname::size: stack_size--;
break; break;
default: }
break; case 1:
op->method = methodname::push;
op->value = rand() % 20;
stack_size++;
break;
default:
op->method = methodname::size;
break;
}
} }
}; }
//void generate_operations_uniform(std::vector<operation> *operations, int minVal, int maxVal) {
// int range_size = maxVal - minVal;
// for (auto op = operations->begin(); op != operations->end(); op++) {
// op->input = (rand() % range_size) + minVal;
// switch (rand() % 3) {
// case 0:
// op->method = methodname::add;
// break;
// case 1:
// op->method = methodname::rmv;
// break;
// default:
// op->method = methodname::ctn;
// break;
// }
// }
//}
//void generate_operations(std::vector<operation> *operations, int minVal, int maxVal, int i) {
// int range_size = maxVal - minVal;
// for (auto op = operations->begin(); op != operations->end(); op++) {
// op->input = (rand() % range_size) + minVal;
// if (rand() % 100 < i) {
// op->method = methodname::ctn;
// } else if (rand() % 10 < 9) {
// op->method = methodname::add;
// } else {
// op->method = methodname::rmv;
// }
// }
// DEBUG_MSG("Generated operations with i = "<< i);
//}
//void run_worker(std::vector<operation>* operations, Set* set) { //void run_worker(std::vector<operation>* operations, Set* set) {
// DEBUG_MSG("Run worker"); // DEBUG_MSG("Run worker");