-
Notifications
You must be signed in to change notification settings - Fork 0
/
VirusList.cpp
179 lines (129 loc) · 4.54 KB
/
VirusList.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "VirusList.h"
using namespace std;
void VirusListPrint(VirusNode * head){
VirusNode * current = head;
cout << "Printing the list with the viruses: " << endl;
int i = 1;
while (current != NULL) {
cout << "Virus name " << i++ << ": " << current->virusName << endl;
current = current->next;
}
cout << endl;
}
/* Add an element to the beginning of the list (pushing to the list) */
void VirusListPush(VirusNode ** head, string virusName, int bloomFilterSize){
VirusNode * newNode = new VirusNode;
/* Update data */
newNode->virusName = virusName;
newNode->bloomFilter = new BloomFilter(bloomFilterSize);
newNode->Vaccinated = new SkipList(MAX_HEIGHT);
newNode->NotVaccinated = new SkipList(MAX_HEIGHT);
newNode->next = *head;
/* Now the new VirusNode will be the list's head */
*head = newNode;
}
Date* VirusListCheckIdForVirus(VirusNode* head, int keyId, string virusName){
VirusNode* current = head;
CitizenNode* cit;
VInfoNode* found;
while (current != NULL) {
if (current->virusName.compare(virusName) == 0){ // find the virus
if (current->Vaccinated->SkipListSearch(keyId,&cit)){ /* If person is vaccinated */
found = VInfoListSearch2(cit->citizen.citizenIDptr,current->virusName);
return found->vacInfo.dateVaccinated;
}
return NULL;
}
current = current->next;
}
return NULL;
}
int VirusSearchIdInBloom(VirusNode* head, string citizenId, string virusName){
VirusNode* current = head;
while (current != NULL){ /* For each virus until we find virus called "virusName" */
if (current->virusName.compare(virusName) == 0)
return current->bloomFilter->BloomFilterSearch(citizenId); /* Search virusName's bloom filter for citizenId => Return 1 or 0 */
current = current->next; /* Go to the next virus */
}
cout << "There is no virus called: " << virusName << endl;
return 0;
}
/* Return the address of VirusNode if "virusName" is in Virus List or NULL if it isn't */
VirusNode* VirusGetNode(VirusNode* head, string virusName){
VirusNode* current = head;
while (current != NULL){
if (current->virusName.compare(virusName) == 0)
return current;
current = current->next;
}
cout << "There is no virus called: " << virusName << endl;
return NULL;
}
int VirusPrintNotVacList(VirusNode* head, string virusName){
VirusNode* current = head;
while (current != NULL){
if (current->virusName.compare(virusName) == 0){
current->NotVaccinated->SkipLevelPrint(0);
return 1;
}
current = current->next;
}
return 0;
}
/* Return "true" if "virusName" is in Virus List or "false" if it isn't */
bool VirusListSearch(VirusNode* head, string virusName){
VirusNode* current = head;
while (current != NULL) {
if (current->virusName.compare(virusName) == 0)
return true;
current = current->next;
}
return false;
}
char* VirusGetBloomArray(VirusNode* head, string virusName){
VirusNode* current = head;
while (current != NULL) {
if (current->virusName.compare(virusName) == 0) {
return current->bloomFilter->getBloom();
}
current = current->next;
}
return NULL;
}
string VirusListGetVirusName(VirusNode* head, int index){
if (index > VirusListCount(head)){
perror("Out on limits");
exit(1);
}
VirusNode* current = head;
for (int i = 1; i <= index; i++){
current = current->next;
}
if (current != NULL)
return current->virusName;
else
return "";
}
/* Return the number of nodes = different viruses in the list */
int VirusListCount(VirusNode* head){
VirusNode* current = head;
int counter = 0;
while (current != NULL) {
current = current->next;
counter++;
}
return counter;
}
/* Delete all nodes => delete list */
void VirusDeleteList(VirusNode** head){
VirusNode* current = *head;
VirusNode* temp = NULL;
while (current != NULL) {
temp = current;
current = current->next;
delete temp->bloomFilter; /* Delete the bloom filter */
delete temp->Vaccinated; /* Delete vaccinated skip list */
delete temp->NotVaccinated; /* Delete not vaccinated skip list */
delete temp; /* Delete VirusNode */
}
}