-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_data.cpp
More file actions
executable file
·57 lines (47 loc) · 1.53 KB
/
Copy pathgenerate_data.cpp
File metadata and controls
executable file
·57 lines (47 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <fstream>
#include <vector>
#include <string>
#define NOP (1UL << 12)
#define DISTINCT_KEYS (1UL << 10)
#define INSERT_RATIO 0.3
#define UPDATE_RATIO 0.3
#define DELETE_RATIO 0.2
#define QUERY_RATIO 0.1
#define RANGE_QUERY_RATIO 0.1
int main()
{
std::vector<double> prob = {INSERT_RATIO};
for (auto r : {UPDATE_RATIO, DELETE_RATIO, QUERY_RATIO, RANGE_QUERY_RATIO})
prob.push_back(r + prob.back());
//std::vector<double> prob = {0.3, 0.6, 0.8, 0.9, 1.0};
// insert update delete query range_query
uint64_t key, ed;
double t;
FILE* destFile = fopen("parser_in.txt", "w");
for (auto i = 0; i < NOP; i++)
{
t = rand() / double(RAND_MAX);
key = rand() % DISTINCT_KEYS;
ed = rand() % DISTINCT_KEYS;
if (key > ed)
std::swap(key, ed);
if (t <= prob[0]) {
fprintf(destFile, "Insert %lu %lu_v%d\n", key, key, rand() % 10);
} else if (t <= prob[1]){
fprintf(destFile, "Update %lu %lu_v%d\n", key, key, rand() % 10);
} else if (t <= prob[2]){
fprintf(destFile, "Delete %lu\n", key);
} else if (t <= prob[3]){
fprintf(destFile, "Query %lu\n", key);
} else if (t <= prob[4]){
fprintf(destFile, "Range_query %lu %lu\n", key, ed);
}
}
if (destFile)
fclose(destFile);
printf("Generating rand values..Done!\n");
return 0;
}