-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiseaseMain.cpp
118 lines (96 loc) · 3.46 KB
/
diseaseMain.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
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
#include <iostream>
#include <string>
#include <fstream>
#include <bits/stdc++.h>
#include "ClassLinkedList.h"
#include "ClassLinkedListNode.h"
#include "ClassRecord.h"
#include "Auxiliary.h"
#include "ClassAVLTreeNode.h"
#include "ClassAVLTree.h"
#include "ClassHashTable.h"
#include "ClassHeapTree.h"
#include "ClassHeapTreeNode.h"
using namespace std;
int main(int argc, char **argv){
string* patientRecordsFile;
string* dhtNumOfEntriesStr;
string* chtNumOfEntriesStr;
string* bucketSizeStr;
int diseaseHashtableNumOfEntries;
int countryHashtableNumOfEntries;
int bucketSize;
//Getting the values of given arguments
patientRecordsFile = getArgument("-p", argc, argv);
dhtNumOfEntriesStr = getArgument("-h1", argc, argv);
chtNumOfEntriesStr = getArgument("-h2", argc, argv);
bucketSizeStr = getArgument("-b", argc, argv);
diseaseHashtableNumOfEntries = stoi(*dhtNumOfEntriesStr);
countryHashtableNumOfEntries = stoi(*chtNumOfEntriesStr);
bucketSize = stoi(*bucketSizeStr);
ifstream infile;
infile.open(*patientRecordsFile);
string line;
Record* recordPtr;
string* countryStr;
string* diseaseStr;
LinkedList list;
HashTable hashTable1(countryHashtableNumOfEntries);
HashTable hashTable2(diseaseHashtableNumOfEntries);
while (getline(infile, line)) {
recordPtr = new Record(line, false);
if(!(list.contains(recordPtr->getRecordId()))){
list.insertItem(recordPtr); //List of Records creation
countryStr = new string(recordPtr->getCountry());
diseaseStr = new string(recordPtr->getDisease());
hashTable1.insertItem(countryStr, bucketSize, recordPtr);
hashTable2.insertItem(diseaseStr, bucketSize, recordPtr);
}
}
infile.close();
int i, count;
bool exit = 0;
string str;
while(!exit){
cout << "Type the query and its requirements: ";
getline(cin, str);
count = getCountOfArgs(str);
string* ArrayOfStrings = new string[count];
istringstream ss(str);
string word;
// Traverse through all words and keep them in an array
i = 0;
while(ss >> word) {
ArrayOfStrings[i] = word;
i++;
}
if(ArrayOfStrings[0] == "/globalDiseaseStats"){
firstQuery(hashTable2, ArrayOfStrings, count);
}else if(ArrayOfStrings[0] == "/diseaseFrequency"){
secondQuery(hashTable2, ArrayOfStrings, count);
}else if(ArrayOfStrings[0] == "/topk-Diseases"){
thirdQuery(list, ArrayOfStrings, count);
}else if(ArrayOfStrings[0] == "/topk-Countries"){
fourthQuery(list, ArrayOfStrings, count);
}else if(ArrayOfStrings[0] == "/insertPatientRecord"){
fifthQuery(list, ArrayOfStrings, count);
}else if(ArrayOfStrings[0] == "/recordPatientExit"){
sixthQuery(list, ArrayOfStrings);
}else if(ArrayOfStrings[0] == "/numCurrentPatients"){
seventhQuery(hashTable2, ArrayOfStrings, count);
}else if(ArrayOfStrings[0] == "/exit"){
exit = 1;
cout << "Exiting..." << endl;
}else{
cout << "Wrong input. Please try again!" << endl;
}
delete[] ArrayOfStrings;
}
delete patientRecordsFile;
delete dhtNumOfEntriesStr;
delete chtNumOfEntriesStr;
delete bucketSizeStr;
delete recordPtr;
delete countryStr;
delete diseaseStr;
}