-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (60 loc) · 1.55 KB
/
main.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
#include <fstream>
#include <cstdlib>
#include "Rtree.h"
int main(int argc, char const *argv[]){
std::ifstream inp;
std::ofstream out;
if( argc < 5) std::cout << "Give correct parameters";
FileManager fm;
FileHandler fh;
try{
fh = fm.CreateFile("RTREE_INDEX.txt");
}
catch(...){
std::remove("RTREE_INDEX.txt");
fh = fm.CreateFile("RTREE_INDEX.txt");
}
inp.open (argv[1]);
out.open(argv[4]);
int maxCap = atoi(argv[2]);
int dimensionality = atoi(argv[3]);
Btree rt = Btree(dimensionality,maxCap,fh);
std::string line;
while(inp >> line){
if(line == "BULKLOAD"){
std::string bulkFile;
inp >> bulkFile;
int numpoints;
inp >> numpoints;
out << "BULKLOAD\n\n";
FileHandler fh1 = fm.OpenFile(bulkFile.c_str());
rt.bulk_load(fh1,fh,numpoints);
fm.CloseFile(fh1);
}
else if( line == "INSERT"){
std::vector< int > p(2*dimensionality);
for(int i = 0; i < dimensionality ; i++){
inp >> p[2*i];
p[2*i + 1] = p[2*i];
}
out << "INSERT\n\n";
rt.Insert(p,fh);
}
else if( line == "QUERY"){
std::vector< int > p(2*dimensionality);
for(int i = 0; i < dimensionality ; i++){
inp >> p[2*i];
p[2*i + 1] = p[2*i];
}
if (rt.Search(p,rt.rootPageId,fh)) out << "TRUE\n\n";
else out << "FALSE\n\n";
}
else std::cerr <<"Input file incorrect\n";
}
inp.close();
out.close();
fm.CloseFile(fh);
fm.DestroyFile("RTREE_INDEX.txt");
// std::cout <<"Excution finished with success\n";
return 0;
}