-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateFile.cpp
100 lines (80 loc) · 2.32 KB
/
GenerateFile.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
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
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream> //For reading inputfile
#include <stdlib.h> //exit, EXIT_FAILURE
#include <limits.h> //random limits
#include <math.h>
#include <random>
#include "GenST.h"
using namespace std;
uint getRandom(uint min, uint max){
uint u1 = 0x0000ffffU & (uint) rand();
uint u2 = 0x0000ffffU & (uint) rand();
u1 = u1 << 16;
u1 = u1 | u2;
if((max - min) == UINT_MAX){
return u1;
} else {
return min + (u1 % (max - min + 1));
}
}
void testTable(uint B, uint R, uint S, uint h, string probename, string inputname){
SplashTable sTable(B, R, S, h);
uint lim = exp2(S-1);
//Key limit
uint keyLim = exp2(32)-1;
//Arrays holding generated keys
uint *keys = new uint[lim];
uint *payloads = new uint[lim];
ofstream probeFile, inputFile;
probeFile.open(probename);
inputFile.open(inputname);
int notFirst = 0;
for(uint i = 0; i < lim; i++){
do{
keys[i] = getRandom(1,keyLim-1);
} while(sTable.probe(keys[i]));
payloads[i] = getRandom(1,keyLim-1);
if(sTable.insert(keys[i], payloads[i], 0, -1)){
inputFile << keys[i] << " " << payloads[i] << "\n";
if(getRandom(0,1)){
if(notFirst){
probeFile << "\n";
}
probeFile << keys[i];
notFirst = 1;
}
} else {
break;
}
}
probeFile.close();
inputFile.close();
delete [] keys;
delete [] payloads;
}
int main(int argc, char* argv[]){
uint B, R, S, h;
string probefile;
string inputfile;
srand( time(0));
//Initialize arguments
switch (argc) {
case 7: //No dumpfile
B = stoi(argv[1]);
R = stoi(argv[2]);
S = stoi(argv[3]);
h = stoi(argv[4]);
probefile=argv[5];
inputfile=argv[6];
break;
default:
cout << "Missing arguments:\nB: Bucket size\nR: Recursions\n";
cout << "S: 2^S entries\nh: Hash functions\n";
cout << "probefileout inputfileout\n";
exit(EXIT_FAILURE);
break;
}
testTable(B, R, S, h, probefile, inputfile);
}