私は今、ファイルからデータをエンコード/デコードするプログラムを書いています。
アルファベット: 8 ビット ASCII コード
したがって、このアルファベットには n = 256 のシンボルがあり、ヒープの最大数は 2n-1 = 511 です。
適応ハフマン コーディングのアルゴリズムは理解していますが、これを実装する際にいくつか問題があります。
コードの最初の部分を書きましたが、うまくいくには助けが必要です。
#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 */
}
手順へのリンクは次のとおりです。アルゴリズム
- 私のツリー構造は正しいですか?
- アルファベットはどのように保管すればよいですか?コードに関する構造を書きましたが、シンボルのリストをどうするかわかりません -> struct huffcode
- ヒープなどの重みを増やす方法は知っていますが、それ以上はできません。「このシンボルを以前に見たことがある/ツリーでこのシンボルを使用するのは初めてです」という問題があります