-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_seeder.h
56 lines (48 loc) · 1.09 KB
/
data_seeder.h
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
#ifndef DATA_SEEDER_H_
#define DATA_SEEDER_H_
#include <vector>
#include <sstream>
#include <cstdlib>
std::string itos(int x)
{
std::ostringstream oss;
oss << x;
return oss.str();
}
class DataSeeder
{
public:
DataSeeder(int max_size) :size(0)
{
for (int i = 0; i < max_size; ++i){
data.push_back(itos(i));
}
}
std::string key_for_get()
{
int k = rand() % size;
return data[k];
}
std::string key_for_del()
{
int k = rand() % size;
std::string res = data[k];
--size;
data[k] = data[size];
data[size] = res;
return res;
}
std::string key_for_put()
{
int k = rand() % (data.size() - size) + size;
std::string tmp = data[size];
data[size] = data[k];
data[k] = tmp;
++size;
return data[size - 1];
}
private:
int size;
std::vector<std::string> data;
};
#endif //DATA_SEEDER_H_