-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.cpp
60 lines (51 loc) · 1.93 KB
/
gen.cpp
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
58
59
60
#include <iostream>
#include <fstream>
#include <random>
using namespace std;
int main(int argc, char* argv[]) {
if (argc < 4) {
cerr << "Expected 3 arguments: seed, numOperations, and keyUpperBound\n";
return 1;
}
const string OPTIONS[3] = {"search", "insert", "delete"};
unsigned seed = atoi(argv[1]);
unsigned numOperations = atoi(argv[2]);
unsigned keyUpperBound = atoi(argv[3]);
minstd_rand rng(seed);
uniform_int_distribution<unsigned> valGen(0, keyUpperBound);
discrete_distribution<unsigned> optGen({40, 40, 20}); // 40% search, 40% insert, 20% delete
discrete_distribution<int> signGen({50, 50}); // 50% negative, 50% positive
ofstream input0("test/input-0.txt");
for (unsigned i = 0; i < numOperations; i++) {
unsigned opt = optGen(rng);
unsigned val = valGen(rng);
input0 << OPTIONS[opt] << " " << val << "\n";
}
ofstream input1("test/input-1.txt");
unsigned val = valGen(rng) * 2 + 1;
unsigned M = 1;
while (M < keyUpperBound/2) M *= 2;
for (unsigned i = 0; i < 300; i++) {
input1 << OPTIONS[1] << " " << (val + i*64) % M << "\n";
}
for (unsigned i = 0; i + 300 < numOperations; i++) {
unsigned opt = optGen(rng);
input1 << OPTIONS[opt] << " " << (val + i*64) % M << "\n";
}
ofstream input2("test/input-2.txt");
val = valGen(rng) * 2 + 1;
for (unsigned i = 0; i < 300; i++) {
input2 << OPTIONS[1] << " " << (val + i*2) % keyUpperBound << "\n";
}
for (unsigned i = 0; i + 300 < numOperations; i++) {
unsigned opt = optGen(rng);
input2 << OPTIONS[opt] << " " << (val + i) % keyUpperBound << "\n";
}
ofstream input3("test/input-3.txt");
for (unsigned i = 0; i < numOperations; i++) {
unsigned opt = optGen(rng) ? 1 : 0; // 40% search, 60% insert
val = valGen(rng);
input3 << OPTIONS[opt] << " " << val << "\n";
}
return 0;
}