-
Notifications
You must be signed in to change notification settings - Fork 1
/
huffman.h
174 lines (146 loc) · 4.12 KB
/
huffman.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
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
#ifndef HUFFMAN_H
#define HUFFMAN_H
// Struture Data Types
typedef struct node
{
char character;
int frequency;
struct node *left;
struct node *right;
struct node *next;
} NODE;
typedef struct table
{
char character;
unsigned int num;
int size;
struct table *next;
} TABLE;
// Function Names
/*
* Prints the correct format to be used to run the program
*/
void message();
/*
* Starts the process of encoding or decoding
* encode() => converts the file to .huff extension
* decode() => converts the file to respective extension
*/
void process(char *argv[]);
/*
* Starts the process of encoding the file
* Uses Linked List and Tree Structure to encode the file
* Uses method of Huffman Encoding
*/
void encode(NODE **head, const char *filename);
/*
* Starts the process of encoding the file
* Uses Linked List and Tree Structure to encode the file
*/
void decode(TABLE **head, const char *filename);
/*
* Implication of Linked List Merge Sort
* Time Complexity => O(n*log(n))
*/
/*
* MergeSort Function
* Keeps calling split function recursively
* Applies merge sort when there is two nodes
*/
void mergeSort(NODE **head);
/*
* SortedMerged Function
* Combines both small linked list into bigger one
* according to ascending order
*/
NODE *sortedMerge(NODE *a, NODE *b);
/*
* Split Function
* Splits the linked list into two
* Similar method to hare and tortise method
*/
void split(NODE *source, NODE **fhead, NODE **bhead);
/*
* Prints the binary tree
* Uses recursion to print the tree
* Prints in the format <- Left -> <- Right -> <- Root -> (Post Order Traversal)
*/
void printTree(NODE *cur);
/*
* Function that converts Linked list into Tree Structure
* Takes input as a Linked list and returns a Tree Structure
*/
void createTree(NODE **head);
/*
* Function that updates list
* Function that takes subtree and adds to the linked list in ascending order
*/
void updateList(NODE **head, NODE *node);
/*
* Function that creates a node
* Takes two node with minimum frequency of character and creates a new node
* making a subtree
*/
NODE *addNode(NODE *node1, NODE *node2);
/*
* Function that creates a table node
* Takes a character, character encoded value, and size of it
* which is used to make a linked list
*/
TABLE *getTableNode();
/*
* Function that creates a table
* Takes a character and character encoded value, and size of it
* value is 'unsigned int' calculated in binary
*/
void createTable(TABLE **header, NODE *cur, unsigned int number, int size);
/*
* Function that prints the table
* Takes a table and prints the table in the format
*/
void printTable(TABLE *head);
/*
* Function that checks if file exists
* returns 1 if file exists and 0 if file doesn't exist
*/
int fileExists(char *filename);
/*
* Checks correct file extension used for a file
* returns 1 if extension is present else 0
*/
int checkExtension(char *filename, char *extension);
/*
* Function that goes through if the parameters and file names are correct
* returns 1 if error else 0
* argv[1] = -encode or -decode
* argv[2] = <file name>
*/
int conditions(char *argv[]);
/*
* On work in naming the output file
*/
char *fileName(const char *filename);
/*
* Function that finds the node that search based on the character
*/
TABLE *findNode(TABLE *head, char c);
/*
* Function that startes the process of encoding the file
* Writes the data to the file in the form of binary
* Contains the table data and encoded data and also the offset of last character
*/
void fileEncoding(TABLE *head, const char *filename);
/*
* Function that release the memory of NODE structure data type
*/
void freeSpace(NODE **head);
/*
* Function that release the memory of TABLE structure data type
*/
void freeTable(TABLE **head);
/*
* Function that checks if the value and size associated with character is present in the table
* if so returns the character or else return '\0'
*/
char findCharacter(TABLE *head, unsigned int number, int size);
#endif