-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathht.h
More file actions
48 lines (41 loc) · 1.7 KB
/
ht.h
File metadata and controls
48 lines (41 loc) · 1.7 KB
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
#ifndef HUFFTREE_H
#define HUFFTREE_H
typedef struct HuffmanNode HuffmanNode;
typedef struct HuffmanTree HuffmanTree;
typedef struct HuffmanNode
{
unsigned char value; // the character value of
unsigned int frequency; // Freq of the byte within the file
unsigned int hcode; // the code of the node represented in the huffman tree
unsigned char codelength;
HuffmanNode *left; // NULL if dne
HuffmanNode *right; // NULL if dne
} HuffmanNode;
typedef struct HuffmanTree
{
unsigned int bytecount; // total # of bytes in read file
unsigned int count; // total number of nodes within the tree
unsigned int maxfreq; // Largest frequency of a byte present within the file
HuffmanNode *tree[512]; // Huffman tree can be statically declared
HuffmanNode *root;
} HuffmanTree;
// funcs
int DoHTCompression(FILE *fp);
int DoHTDecompression(FILE *fp);
HuffmanTree *InitHT();
int FreeHT(HuffmanTree *ht);
int InitializeLeafNodes(FILE *inputFile, HuffmanTree *ht);
int BuildHTFromFrequencies(HuffmanTree *ht);
int GetCodeFromCharacter(HuffmanTree *ht, unsigned char value);
int GetCharacterFromCode(HuffmanTree *ht, unsigned int code, unsigned char len);
int WriteTreeToFile(HuffmanTree *ht, FILE *output);
int WriteDataToFile(HuffmanTree *ht, FILE *input, FILE *output);
HuffmanTree *ReadTreeFromFile(FILE *input);
int ReadDataFromFile(HuffmanTree *ht, FILE *input, FILE *output);
int PrintNodes(HuffmanTree *ht);
int PrintNode(HuffmanTree *ht, int index, const char *opening);
void PrintTreeInformation(HuffmanTree *ht, const char *opening);
// optimized functions
int WriteCompressedTreeToFile(HuffmanTree *ht, FILE *output);
HuffmanTree *ReadCompressedTreeFromFile(FILE *input);
#endif