ITPub博客

首页 > IT职业 > IT生活 > 聪明的以色列人(下):LZ78 和 LZW (转)

聪明的以色列人(下):LZ78 和 LZW (转)

原创 IT生活 作者:amyz 时间:2007-11-16 18:11:27 0 删除 编辑
聪明的以色列人(下):LZ78 和 LZW (转)[@more@]

LZ78 的算法描述:

for (;;) { current_match = 1; current_length = 0; memset(test_string, '', MAX_STRING); for (;;) { test_string[current_length ++] = getc(input); new_match = find_match(test_string); if (new_match) == -1) break; current_match = new_match; } output_code(current_match); output_char(test_string[current_letgth - 1]; add_string_to_dictionary(test_string); }


LZ78 示例:

输入正文: "DAD DADA DADDY DADO..." 输出短语 输出字符 编码后的串 0 'D' "D" 0 'A' "A" 1 ' ' "D" 1 'A' "DA" 4 ' ' "DA " 4 'D' "DAD" 1 'Y' "DY" 0 ' ' " " 6 'O' "DADO" 此时字典的情况: 0 "" 1 "D" 2 "A" 3 "D " 4 "DA" 5 "DA " 6 "DAD" 7 "DY" 8 " " 9 "DADO"


 


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-982771/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    3982
  • 访问量
    7892430