This repository has been archived by the owner on Sep 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
86 lines (68 loc) · 2.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <math.h>
#include "storage.cpp"
#include "record.h"
#include "bptree.cpp"
using namespace std;
int main()
{
ifstream inputfile("data.tsv");
string inputstring;
size_t datastoragesize = 150000000;
size_t indexstoragesize = 350000000;
size_t blocksize = 200;
Storage dbstorage(datastoragesize, blocksize);
Storage instorage(indexstoragesize, blocksize);
BPTree bptree(blocksize, &dbstorage, &instorage);
int i = 1;
while(getline(inputfile, inputstring)){
if(inputstring.rfind("tconst", 0) == 0){
continue;
}
vector <string> inputtoken;
istringstream iss(inputstring);
string word;
while(getline(iss, word, '\t')){
inputtoken.push_back(word);
}
Record record;
strcpy(record.tconst, inputtoken[0].c_str());
record.avgRating = stod(inputtoken[1]);
record.numVotes = stoi(inputtoken[2]);
void* recptr = nullptr;
//cout << "Rcdptr: " << dbstorage.addRecord(inputtoken[0], stod(inputtoken[1]), stoi(inputtoken[2])) << endl;
recptr = dbstorage.writeToDisk(&record, sizeof(record));
cout << "tconst: " << record.tconst << " - numvotes: " << record.numVotes << endl;
if(record.numVotes == 1572){
cout << "Split root" << endl;
}
bptree.inserttotree(stoi(inputtoken[2]), recptr);
/*
for(int i = 0; i < bptree.maxkeyspernode; i++){
cout << bptree.root->keyptr[i].key << " : " << bptree.root->keyptr[i].dataptr << endl;
if(bptree.root->keyptr[i+1].dataptr == nullptr){
cout << endl;
break;
}
}
*/
}
/*
for(int i=0;i<dbstorage.datapointers.size();i++){
Record* testptr = (Record*) dbstorage.datapointers[i];
cout << "Record: " << testptr->tconst << " - " << testptr->avgRating << " - " << testptr->numVotes << " : " << testptr << endl;
}
*/
//cout << "Block Size: " << blocksize << endl;
//cout << "Number of records per block: " << dbstorage.numofrecordsperblock << endl;
cout << "===== Experiment 1 =====" << endl;
//cout << "Number of blocks: " << dbstorage.getNumberOfDataBlocks() << endl;
//cout << "Size of database: " << blocksize * dbstorage.getNumberOfDataBlocks() / 1000000 << " mb" << endl;
cout << "===== Experiment 2 =====" << endl;
bptree.displaytree(bptree.root, 0);
inputfile.close();
}