⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter6.htm

📁 压缩/解压缩类源码
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>笨笨数据压缩教程</title>
</head>

<body bgcolor="#FFFFFF">

<p align="right"><a href="http://www.contextfree.net/">返回断章取义堂</a>&nbsp;&nbsp;<a href="http://www.contextfree.net/wangyg/">返回咏刚的家</a></p>

<p style="background-color:#AAEEFF;font-size:14px;color:#0000AA">《笨笨数据压缩教程》是我在1998年因工作需要研究压缩算法时写的文章(算是一种工作笔记吧,其中难免有许多疏漏),1999年初随着项目变迁,就把压缩技术的研究暂时搁置了。从那以后,一是工作太忙,二是自己懒惰,总之是没能把半部压缩教程补全。非常对不住大家。——王咏刚,2003年3月</p>

<p><img src="benben.jpg"
alt="笨笨数据压缩教程(Benben's Data Compression Guide)"
width="370" height="129"></p>

<h2>第六章 聪明的以色列人(下):LZ78 和 LZW</h2>
<div align="right">

<address>
    <a href="chapter5.htm">第五章</a> <a href="chapter7.htm">第七章</a>
</address>
</div>

<p>LZ78 的算法描述:</p>

<pre>for (;;)
{
    current_match = 1;
    current_length = 0;
    memset(test_string, '\0', 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);
}</pre>

<p>LZ78 示例:</p>

<pre>输入正文: &quot;DAD DADA DADDY DADO...&quot;
输出短语      输出字符      编码后的串
 0              'D'         &quot;D&quot;
 0              'A'         &quot;A&quot;
 1              ' '         &quot;D&quot;
 1              'A'         &quot;DA&quot;
 4              ' '         &quot;DA &quot;
 4              'D'         &quot;DAD&quot;
 1              'Y'         &quot;DY&quot;
 0              ' '         &quot; &quot;
 6              'O'         &quot;DADO&quot;

此时字典的情况:

0          &quot;&quot;
1          &quot;D&quot;
2          &quot;A&quot;
3          &quot;D &quot;
4          &quot;DA&quot;
5          &quot;DA &quot;
6          &quot;DAD&quot;
7          &quot;DY&quot;
8          &quot; &quot;
9          &quot;DADO&quot;</pre>

<p> </p>
<div align="center"><center>

<address>
    <a href="chapter5.htm">第五章</a> <a href="chapter7.htm">第七章</a>
</address>
</center></div><div align="right">

<address>
    有问题吗?有建议吗?快给王笨笨写信:wangyg@contextfree.net
</address>
</div><div align="right">

<address>
    <strong>章节书签:</strong><a href="default.htm">前言</a>
    <a href="content.htm">目录</a> <a href="chapter1.htm">1</a>
    <a href="chapter2.htm">2</a> <a href="chapter3.htm">3</a> <a
    href="chapter4.htm">4</a> <a href="chapter5.htm">5</a> <a
    href="chapter6.htm">6</a> <a href="chapter7.htm">7</a> <a
    href="chapter8.htm">8</a> <a href="chapter9.htm">9</a> <a
    href="chapter10.htm">10</a> <a href="chapter11.htm">11</a> <a
    href="chapter12.htm">12</a> 
</address>
</div>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -