如图 范式霍夫曼编码 遇到这种 编码长度不连续的情况
网上说
extern KBitInputStream bs;
int len = 1;
int code = bs.ReadBit();
while(code >= first[len])
{
code <<= 1;
code |= (bs.ReadBit()); // append next input bit to code
len++;
}
len--;
// 至此,识别出了一个前缀码,下面将code解码为其对应的符号sym
int index = index[len]+(code-first[len]);
int sym = table[index];
但是 first[3] 和 first[4] 应该 是多少呢? 我写成跟 first[5]一样 都是 2 这样 可以识别 00 但是 不能识别 00011 求帮助啊 !!!
备注:first[i]表示长度为i的第一个码字的整数值。根据约定3,即first[3] = 0可得到符号a的范式哈夫曼编码为000。再根据约定2,可得到first[4] = 2*(first[3]+1) = 2,进一步可知b的编码为0010。由约定1可构造出符号c的编码为0011,由此类推可构造出整个码字空间如下:
a=000(0); f=0110(6); k=10101(21);
b=0010(2); g=0111(7); ...
c=0011(3); h=1000(8); u=11111(31);
d=0100(4); i=1001(9);
e=0101(5); j=10100(20);
其中first[3] = 0, first[4] = 0010b = 2, first[5] = 10100b = 20
但是 first[3] 和 first[4] 应该 是多少呢? 我写成跟 first[5]一样 都是 2 这样 可以识别 00 但是 不能识别 00011 求帮助啊 !!!