i am writing right now program thats should encode/decode data from file.
Alphabet: 8-bit ASCII codes
So i have n = 256 symbols in this alphabet, max number of heaps is 2n-1 = 511
I understand algorithm of adaptive huffman coding but i have some problems with implement this.
I wrote first part of my code, but i need some help to go on good way.
#define FIRST_NYT 511
struct huffcode {
int nbits;
int code;
};
typedef struct huffcode code;
struct huffheap {
char symbol; /* character contained in tree node */
int weight; /* number of times symbol has occured in file so far */
int order; /* ordering system, root has order number 511 */
struct huffheap *left;
struct huffheap *right;
struct huffheap *parent;
};
typedef struct huffheap *heap;
static heap heap_create(int symbol, struct heap *root){
/* if tree is empty, add root */
if(heap = NULL) {
heap = (huffheap*)malloc(sizeof(*heap));
heap- >symbol = /* i dont know what i should when heap doesnt has a symbol like NYT */
heap- >weight = 0;
heap- >order = FIRST_NYT;
heap- >left = NULL;
heap- >right = NULL;
heap- >parent = NULL;
}
/* TO_DO: check -> is the first time of this symbol ? */
/* if yes -> add node */
}
Here is the link to procedure: Algorithm
- Is my tree structure is correct?
- How i should store the alphabet? I wrote a structure about code but i dont know what to do with list of symbols -> struct huffcode
- I know how i can increment weight of heaps etc. but i cant go further. I have problem with "Seen this symbol before/Is the first time of this symbol in tree"