-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchStringTypes.cpp
More file actions
203 lines (191 loc) · 4.86 KB
/
Copy pathchStringTypes.cpp
File metadata and controls
203 lines (191 loc) · 4.86 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# include "chStringTypes.h"
// A constructor
Rchar_string :: Rchar_string()
{
N = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a string made from given character set
void Rchar_string :: generate(int n, Timer &t1, string s)
{
vector <int> chars;
Distribution :: FillArray(chars, n, 0, (int)s.size() - 1, false, t1);
for(int i = 0; i < n; i++)
{
fout << s[chars[i]];
t1.time(1);
}
fout << '\n';
}
// A function that generates strings made from given character set test case files
void Rchar_string :: setCase(string &s, int T, int t, int n, string S, int v, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating char_string test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
vector <int> times = numOp :: giveRints(t, n, sz);
N = times.size();
if(pt)
fout << N << '\n';
int tcnt = 0;
for(int j = 0; j < N; j++)
tcnt += times[j];
Timer t1(2 * tcnt);
for(int j = 0; j < N; j++)
{
if(v)
fout << times[j] << '\n';
generate(times[j], t1, S);
}
fout.close();
}
cout << "char_string generation completed." << '\n';
}
// A constructor
R01string :: R01string()
{
N = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a random 01-string
void R01string :: generate(int n, Timer &t1)
{
vector <int> chars;
Distribution :: FillArray(chars, n, 0, 1, false, t1);
for(int i = 0; i < n; i++)
{
fout << chars[i];
t1.time(1);
}
fout << '\n';
}
// A function that generates 01-string test case files
void R01string :: setCase(string &s, int T, int t, int n, int v, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating 01string test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
vector <int> times = numOp :: giveRints(t, n, sz);
N = times.size();
if(pt)
fout << N << '\n';
int tcnt = 0;
for(int j = 0; j < N; j++)
tcnt += times[j];
Timer t1(2 * tcnt);
for(int j = 0; j < N; j++)
{
if(v)
fout << times[j] << '\n';
generate(times[j], t1);
}
fout.close();
}
cout << "01string generation completed." << '\n';
}
// A constructor
Rchar_pair :: Rchar_pair()
{
N = 0;
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a pair of char_strings
void Rchar_pair :: generate(int n, Timer &t1, string S)
{
vector <vector <int> > chars(2);
Distribution :: FillArray(chars[0], n, 0, (int)S.size() - 1, false, t1);
Distribution :: FillArray(chars[1], n, 0, (int)S.size() - 1, false, t1);
for(int j = 0; j < 2; j++)
{
for(int i = 0; i < n; i++)
{
fout << S[chars[j][i]];
t1.time(1);
}
fout << '\n';
}
}
// A function that generates pair of char_string test case files
void Rchar_pair :: setCase(string &s, int T, int t, int n, string S, int v, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating char_pair test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
vector <int> times = numOp :: giveRints(t, n / 2, sz);
N = times.size();
if(pt)
fout << N << '\n';
int tcnt = 0;
for(int j = 0; j < N; j++)
tcnt += times[j];
Timer t1(4 * tcnt);
for(int j = 0; j < N; j++)
{
if(v)
fout << times[j] << '\n';
generate(times[j], t1, S);
}
fout.close();
}
cout << "char_pair generation completed." << '\n';
}
// A constructor
Rchar_array :: Rchar_array()
{
generator.seed(system_clock :: now().time_since_epoch().count());
}
// A function that generates a random array of char_strings
void Rchar_array :: generate(Timer &t1, string s, int m, int n, int v)
{
fout << m;
if(v)
fout << ' ' << n;
fout << '\n';
vector <vector <int> > chars(m);
for(int i = 0; i < m; i++)
Distribution :: FillArray(chars[i], n, 0, (int)s.size() - 1, false, t1);
for(int j = 0; j < m; j++)
{
for(int i = 0; i < n; i++)
{
fout << s[chars[j][i]];
t1.time(1);
}
fout << '\n';
}
}
// A function that generates array of char_string test case files
void Rchar_array :: setCase(string &s, int T, int t, int n, string S, int v, int sz, string &folder_name)
{
int pt = FileOp :: printT(t);
cout << "Generating char_array test files: " << '\n';
for(int i = 0; i < T; i++)
{
FileOp :: setFile(folder_name, s, i, fout);
vector <int> times = numOp :: giveRints(t, n, sz);
if(pt)
fout << (int)times.size() << '\n';
N.clear();
M.clear();
int tcnt = 0;
for(int j = 0; j < (int)times.size(); j++)
{
uniform_int_distribution <int> distribution(1, floor(sqrt(times[j])));
int m = distribution(generator);
M.push_back(m);
N.push_back(times[j] / m);
tcnt += M[j] * N[j];
}
Timer t1(2 * tcnt);
for(int j = 0; j < (int)times.size(); j++)
generate(t1, S, M[j], N[j], v);
fout.close();
}
cout << "char_array generation completed." << '\n';
}