#ifndef HUFFMAN_H #define HUFFMAN_H #include #include #include #define ASCII_SIZE 256 #define ASCII_BYTE_SIZE 8 #define NO_CHAR -1 #define NO_BIT -1 #define TRUE 1 #define FALSE 0 #define LEFT 0 #define RIGHT 1 typedef struct _huff_node { char ascii; int weight; struct _huff_node *left; struct _huff_node *right; struct _huff_node *next; } Huff_Node; void count_weights(char *filename, int *weights); int build_list(Huff_Node **head, int *weights); Huff_Node * create_huff_node(char ascii, int weight); void add_list_node(Huff_Node **headp, Huff_Node *toadd); void print_list(Huff_Node *head); Huff_Node * gen_huff_tree(Huff_Node *head, int weight_total); void print_tree(Huff_Node *root); Huff_Node * remove_min_node(Huff_Node *head); int get_tree_height(Huff_Node *root); int get_tree_height_rh(Huff_Node *root, int height); int get_num_leaves(Huff_Node *root); void get_num_leaves_rh(Huff_Node *root, int *leaves); void gen_codes(Huff_Node * root, int ** codebook); void gen_codes_rh(Huff_Node *root, int ** codebook, int * row, int col); void print_codes(int ** codebook, int numRow); void map_codebook(int ** codebook, int size, int * map); Huff_Node *read_file_header_bits(FILE *fptr); void write_file_header_bits(FILE *fptr, Huff_Node *root, int weight_total, unsigned int num_leaves); void write_file_header_bits_rh(FILE *fptr, Huff_Node *root, unsigned char *bit_pos, unsigned char *cur_byte); void write_ascii_bits(FILE *fptr, char ascii, unsigned char *bit_pos, unsigned char *cur_byte); void write_bit(FILE *fptr, char bit, unsigned char *bit_pos, unsigned char *cur_byte); void read_bit(FILE *fptr, unsigned char *bit, unsigned char *bit_pos, unsigned char * cur_byte); void compress_file(char *filename_in, char *filename_out, int ** codebook, int * map); void decompress_file(char *filename_in, char *filename_out); void write_file_header(FILE *fptr, int *weights); Huff_Node * read_file_header(FILE *fptr); void write_file_data(FILE *fptr_out, FILE *fptr_in, int ** codebook, int * map); char * read_file_data(FILE *fptr, Huff_Node *root); void write_encoded_message(char * data, Huff_Node *root, FILE *out); #endif