-
Notifications
You must be signed in to change notification settings - Fork 0
/
structureFile.h
129 lines (105 loc) · 2.6 KB
/
structureFile.h
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
#define STRING_SIZE 255
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
typedef struct Cell{
char *value;
int version;
Cell *next;
}Cell;
typedef struct Columns{
char *name;
Cell *cell;
Columns *next;
}Columns;
typedef struct Rows{
Columns *columns;
int rowId;
int commitVersion;
Rows *next;
}Rows;
Rows *rowHead = NULL;
Rows *createRowNode(){
Rows *newNode = (Rows *)malloc(sizeof(Rows));
newNode->columns = NULL;
newNode->next = NULL;
return newNode;
}
Columns *createColumnsNode(){
Columns *newNode = (Columns *)malloc(sizeof(Columns));
newNode->name = (char *)malloc(sizeof(char)* STRING_SIZE);
newNode->cell = NULL;
newNode->next = NULL;
return newNode;
}
Cell *createCellNode(){
Cell *newNode = (Cell *)malloc(sizeof(Cell));
newNode->value = (char *)malloc(sizeof(char)* STRING_SIZE);
newNode->next = NULL;
return newNode;
}
Cell *getCellHead(Cell *cellHead, char *value){
Cell *tempNode = cellHead;
Cell *newNode = createCellNode();
strcpy(newNode->value, value);
if (cellHead == NULL)
newNode->version = 1;
else
newNode->version = cellHead->version + 1;
newNode->next = cellHead;
cellHead = newNode;
return cellHead;
}
Columns *getColumnHead(Columns *columnHead, char *columnName, char *value){
Columns *tempNode = columnHead;
while (tempNode != NULL){
if (strcmp(tempNode->name, columnName) == 0){
tempNode->cell = getCellHead(tempNode->cell, value);
return columnHead;
}
tempNode = tempNode->next;
}
tempNode = columnHead;
Columns *newNode = createColumnsNode();
strcpy(newNode->name, columnName);
newNode->cell = getCellHead(newNode->cell, value);
if (columnHead == NULL){
columnHead = newNode;
}
else{
while (tempNode->next != NULL){
tempNode = tempNode->next;
}
tempNode->next = newNode;
}
return columnHead;
}
int getCommitVersion(Rows *row){
int version = INT_MIN;
Columns *tempNode = row->columns;
while (tempNode != NULL){
Cell *cellHead = tempNode->cell, *temp = cellHead;
while (temp != NULL){
if (temp->version > version)
version = temp->version;
temp = temp->next;
}
tempNode = tempNode->next;
}
return version;
}
void printDetails(Rows *row){
Columns *tempNode = row->columns;
while (tempNode != NULL){
Cell *cellHead = tempNode->cell, *temp = cellHead;
while (temp != NULL){
if (temp->version <= row->commitVersion){
printf("%-15s: %-15s\n", tempNode->name, temp->value);
break;
}
temp = temp->next;
}
tempNode = tempNode->next;
}
}