-
Notifications
You must be signed in to change notification settings - Fork 2
/
list.c
293 lines (221 loc) · 7.66 KB
/
list.c
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/* Authors Kazakos Vasileios , Farao Georgios , Manolis Stivaktas */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "list.h"
#include "jsonParser.h"
#include "RBtree.h"
#include "HashTable.h"
#include "helpFunctions.h"
#include "dataList.h"
#include "logistic_regression.h"
#include "thread.h"
/* Creating new list */
list * new_list(void)
{
list * mylist = malloc(sizeof( list));
mylist->start = NULL;
mylist->end = NULL;
mylist->print_flag = 0;
mylist->size=0;
mylist->Removed_duplicates=0;
mylist->different_cliques = NULL;
mylist->printed_different_cliques = NULL;
return mylist;
}
/* Creating new list node */
lnode * new_lnode(char * jsonName)
{
lnode * node = malloc(sizeof(lnode));
node->json_name = malloc(strlen(jsonName) +1);
strcpy(node->json_name,jsonName);
node->next = NULL;
node->file_node=NULL;
return node;
}
/* Inserting list node to list */
void insert_lnode( list* list, lnode* lnode)
{
if(list->start == NULL) /* Checking if list is empty */
{
list->start = lnode;
list->end = lnode;
}
else
{
list->end->next = lnode;
list->end = lnode;
}
list->size = list->size + 1; /* Updating size */
}
/* Deleting list */
void delete_list( list * list)
{
if (list->start == NULL) /* Checking if list is empty */
{
return;
}
else
{
lnode *prev = list->start;
while(list->start != NULL) /* Free allocated memory while moving prev and start pointers */
{
list->start = list->start->next; /* Move list->start to next node */
free(prev->json_name);
free(prev);
prev = list->start; /* Prev indicated to previous state of list->start */
}
}
list->start = list->end = NULL;
list->size = -1; /* So other nodes indicating to the list it's being deleted */
}
/* Deleting first node of list */
void delete_list_node(list * List)
{
struct lnode * tmp = List->start;
List->start = List->start->next; /* Updating list->start */
free(tmp->json_name);
free(tmp);
List->size--; /* Updating size */
}
/* Printing matching json files - basic printing */
void print_list(list * mylist , HashTable * files)
{
FILE * fp = fopen("output.csv", "a");
lnode * temp = mylist->start;
lnode * temp_next;
int index1;
int index2;
struct node * temp_node1;
struct node * temp_node2;
/* Main loop */
/* Printing basic node, and all matching nodes, that are after this node in the list */
/* Move basic node so corresponding pointer indicates to the next node */
/* Continue till basic node is null */
int cnt=rand() %6;
while (temp->next != NULL)
{
temp_next = temp->next;
while (temp_next != NULL)
{
/* find hash indexes */
index1 = hash1(temp->json_name, files->size);
index2 = hash1(temp_next->json_name, files->size);
/* find nodes-json files */
temp_node1 = find_key_RBtree(files->Trees[index1], temp->json_name);
temp_node2 = find_key_RBtree(files->Trees[index2], temp_next->json_name);
train_data * temp_data = new_train_data(temp->json_name, temp_next->json_name , 1);
temp_data->file1_node = temp_node1;
temp_data->file2_node = temp_node2;
lnode_data * node_data =new_lnode_data( temp_data);
if (cnt==5){
insert_lnode_data(test,node_data);
// cnt =0 ;
}
else if(cnt==10){
insert_lnode_data(validation,node_data);
cnt=0;
}
else
insert_lnode_data (data,node_data);
cnt++;
fprintf(fp, "%s, %s\n", temp->json_name , temp_next->json_name);
temp_next = temp_next->next;
}
temp=temp->next;
}
mylist->print_flag = 1; /* So other nodes pointing to list know current list is being printed */
fclose(fp);
}
void print_two_lists(list * mylist1 ,list * mylist2, HashTable * files)
{
FILE * fp = fopen("different.csv", "a");
lnode * temp = mylist1->start;
lnode * temp_next ;
int cnt= rand()%6;
int index1;
int index2;
struct node * temp_node1;
struct node * temp_node2;
while (temp != NULL)
{
temp_next = mylist2->start;
while (temp_next != NULL)
{
/* find hash indexes */
index1 = hash1(temp->json_name, files->size);
index2 = hash1(temp_next->json_name, files->size);
/* find nodes-json files */
temp_node1 = find_key_RBtree(files->Trees[index1], temp->json_name);
temp_node2 = find_key_RBtree(files->Trees[index2], temp_next->json_name);
train_data * temp_data = new_train_data(temp->json_name, temp_next->json_name , 0);
temp_data->file1_node = temp_node1;
temp_data->file2_node = temp_node2;
lnode_data * node_data =new_lnode_data( temp_data);
if (cnt==5){
insert_lnode_data(test,node_data);
// cnt = 0;
}
else if(cnt==10){
insert_lnode_data(validation,node_data);
cnt=0;
}
else
insert_lnode_data (data,node_data);
cnt++;
fprintf(fp, "%s, %s\n", temp->json_name , temp_next->json_name);
temp_next = temp_next->next;
}
temp=temp->next;
}
fclose(fp);
}
void create_validation_list(list * mylist )
{
int i=0;
lnode * temp = mylist->start;
lnode * temp_next;
int index1;
int index2;
struct node * temp_node1;
struct node * temp_node2;
/* Main loop */
/* Printing basic node, and all matching nodes, that are after this node in the list */
/* Move basic node so corresponding pointer indicates to the next node */
/* Continue till basic node is null */
while (temp->next != NULL)
{
temp_next = temp->next;
while (temp_next != NULL)
{
if(i%500==0)
{ /* find nodes-json files */
temp_node1 = temp->file_node;
temp_node2 = temp_next->file_node;
train_data * temp_data = new_train_data(temp->json_name, temp_next->json_name , 1);
temp_data->file1_node = temp_node1;
temp_data->file2_node = temp_node2;
lnode_data * node_data =new_lnode_data( temp_data);
insert_lnode_data(validation,node_data);
if(validation->size%5000==0)
printf("size %d\n",validation->size);
if(i>=VALIDATION_MAX_SIZE)
return;
}
temp_next = temp_next->next;
i++;
}
temp=temp->next;
}
mylist->print_flag = 1; /* So other nodes pointing to list know current list is being printed */
}
void printval()
{
lnode_data * temp = validation->start;
while(temp!=NULL)
{
printf("%s %s \n",temp->data->file1,temp->data->file2);
temp=temp->next;
}
}