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

📄 csdn技术中心 lz77压缩算法(c语言版).htm

📁 是一个压缩文件的算法 用c语言写的
💻 HTM
📖 第 1 页 / 共 4 页
字号:
                <TD align=right><A 
                  href="http://dev.csdn.net/articlelist.aspx?c=10">游戏开发</A>&nbsp;&nbsp;(<A 
                  href="http://www.csdn.net/Rss/RssFeed.aspx?rssid=1&amp;bigclassid=10">rss</A>)&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/articlelist.aspx?c=12">网站制作技术</A>&nbsp;&nbsp;(<A 
                  href="http://www.csdn.net/Rss/RssFeed.aspx?rssid=1&amp;bigclassid=12">rss</A>)&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR></TBODY></TABLE>
            <TABLE style="MARGIN-BOTTOM: 4px" cellSpacing=0 cellPadding=0 
            width="95%" align=center border=0>
              <TBODY>
              <TR>
                <TD style="COLOR: #0033ff; BORDER-BOTTOM: #b0c4de 1px dashed" 
                align=right><FONT style="FONT-SIZE: 8pt">数据库</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/articlelist.aspx?c=8">数据库开发</A>&nbsp;&nbsp;(<A 
                  href="http://www.csdn.net/Rss/RssFeed.aspx?rssid=1&amp;bigclassid=8">rss</A>)&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR></TBODY></TABLE>
            <TABLE cellSpacing=0 cellPadding=0 width="95%" align=center 
border=0>
              <TBODY>
              <TR>
                <TD style="COLOR: #0033ff; BORDER-BOTTOM: #b0c4de 1px dashed" 
                align=right><FONT style="FONT-SIZE: 8pt">软件工程</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/articlelist.aspx?c=13">其他</A>&nbsp;&nbsp;(<A 
                  href="http://www.csdn.net/Rss/RssFeed.aspx?rssid=1&amp;bigclassid=13">rss</A>)&nbsp;&nbsp;&nbsp;&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
      <TABLE cellSpacing=1 cellPadding=0 width="100%" bgColor=#000000 
        border=0><TBODY>
        <TR>
          <TD vAlign=top bgColor=#ededed>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD align=right 
                background="CSDN技术中心 LZ77压缩算法(C语言版).files/top.gif" 
                  height=27><FONT 
              class=fonttitle>积极原创作者&nbsp;</FONT></TD></TR></TBODY></TABLE>
            <TABLE cellSpacing=1 cellPadding=2 width="100%" border=0>
              <TBODY>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/ngnr">ngnr</A>&nbsp;<FONT 
                  color=#ff0000>(21)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/kui">kui</A>&nbsp;<FONT 
                  color=#ff0000>(22)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/met3or">met3or</A>&nbsp;<FONT 
                  color=#ff0000>(1)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/ilzzy">ilzzy</A>&nbsp;<FONT 
                  color=#ff0000>(1)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/ycool1984">ycool1984</A>&nbsp;<FONT 
                  color=#ff0000>(27)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/alexdoes">alexdoes</A>&nbsp;<FONT 
                  color=#ff0000>(15)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/conquer">conquer</A>&nbsp;<FONT 
                  color=#ff0000>(3)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/WonderOne">WonderOne</A>&nbsp;<FONT 
                  color=#ff0000>(2)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/qyii">qyii</A>&nbsp;<FONT 
                  color=#ff0000>(2)</FONT></TD></TR>
              <TR>
                <TD align=right><A 
                  href="http://dev.csdn.net/user/kalex">kalex</A>&nbsp;<FONT 
                  color=#ff0000>(5)</FONT></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>
    <TD vAlign=top width=786>
      <TABLE cellPadding=4 width="100%" border=0>
        <TBODY>
        <TR>
          <TD width=10 height=19></TD>
          <TD height=19>
            <TABLE cellSpacing=3 cellPadding=3 width="100%" border=0>
              <TBODY>
              <TR>
                <TD><A href="http://www.csdn.net/">CSDN</A> - <A 
                  href="http://dev.csdn.net/">文档中心</A> - <FONT color=#003399><A 
                  id=ArticleTitle1_ArticleTitle1_hlClass 
                  href="http://dev.csdn.net/articlelist.aspx?c=9">其他开发语言 
                  </A></FONT></TD>
                <TD align=right>阅读:<SPAN 
                  id=ArticleTitle1_ArticleTitle1_lblReadCount>603</SPAN> 
                  &nbsp;&nbsp;评论: <SPAN 
                  id=ArticleTitle1_ArticleTitle1_lblCommentCount>0</SPAN> 
                  &nbsp;&nbsp; <A 
                  href="http://dev.csdn.net/article/40/40199.shtm#Comment">参与评论</A> 
                </TD></TR></TBODY></TABLE>
            <TABLE cellSpacing=3 cellPadding=3 width="100%" bgColor=#eeeeee 
            border=0>
              <TBODY>
              <TR>
                <TD noWrap width=60 height=0></TD>
                <TD></TD></TR>
              <TR>
                <TD noWrap align=middle bgColor=#003399 height=16><FONT 
                  color=#ffffff>标题</FONT></TD>
                <TD><B>&nbsp; <SPAN 
                  id=ArticleTitle1_ArticleTitle1_lblTitle>LZ77压缩算法(C语言版)</SPAN></B>&nbsp;&nbsp;&nbsp;&nbsp; 
                  选择自 <A id=ArticleTitle1_ArticleTitle1_AuthorLink 
                  href="http://dev.csdn.net/user/www_307">www_307</A> 的 Blog 
              </TD></TR>
              <TR>
                <TD align=middle bgColor=#003399 height=16><FONT 
                  color=#ffffff>关键字</FONT></TD>
                <TD width=500>&nbsp; <SPAN 
                  id=ArticleTitle1_ArticleTitle1_lblKeywords>LZ77压缩算法(C语言版)</SPAN></TD></TR>
              <TR>
                <TD align=middle bgColor=#003399 height=16><FONT 
                  color=#ffffff>出处</FONT></TD>
                <TD>&nbsp; <SPAN 
                  id=ArticleTitle1_ArticleTitle1_lblSource></SPAN></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD width=10></TD>
          <TD><SPAN id=ArticleContent1_ArticleContent1_lblContent><SPAN 
            id=post1 
            style="FONT-SIZE: 12px; COLOR: #000000">测试压缩一个425K的文件需要9.4秒,压缩后的文件为177K。<BR><BR><BR>/*********************************************************************<BR>*<BR>* 
            &nbsp; Project description:<BR>* &nbsp; &nbsp; &nbsp; Lz77 
            compression/decompression 
            algorithm.<BR>*<BR>*********************************************************************/<BR><BR><BR>#include 
            &lt;windows.h&gt;<BR>#include &lt;conio.h&gt;<BR>#include 
            &lt;stdio.h&gt;<BR>#include &lt;assert.h&gt;<BR><BR>#define 
            OFFSET_CODING_LENGTH &nbsp; &nbsp;(10)<BR>#define MAX_WND_SIZE 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;1024<BR>//#define 
            MAX_WND_SIZE &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;(1&lt;&lt;OFFSET_CODING_LENGTH)<BR>#define OFFSET_MASK_CODE 
            &nbsp; &nbsp; &nbsp; &nbsp;(MAX_WND_SIZE-1)<BR><BR>const ULONG 
            &nbsp; &nbsp; m=3;<BR><BR><BR>UCHAR &nbsp; 
            __buffer1__[0x200000];<BR>UCHAR &nbsp; 
            __buffer2__[0x200000];<BR><BR><BR>////////////////////////////////////////////////////////////////////////////////<BR><BR>void<BR>Write1ToBitStream(<BR>&nbsp; 
            &nbsp;PUCHAR &nbsp;pBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulBitOffset<BR>&nbsp; &nbsp;)<BR>{<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulByteBoundary;<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulOffsetInByte;<BR><BR>&nbsp; &nbsp;ulByteBoundary = 
            ulBitOffset&gt;&gt;3 ;<BR>&nbsp; &nbsp;ulOffsetInByte = 
            ulBitOffset&amp;7;<BR><BR>&nbsp; &nbsp;*(pBuffer+ulByteBoundary) |= 
            (1&lt;&lt;ulOffsetInByte);<BR>}<BR><BR>void<BR>Write0ToBitStream(<BR>&nbsp; 
            &nbsp;PUCHAR &nbsp;pBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulBitOffset<BR>&nbsp; &nbsp;)<BR>{<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulByteBoundary;<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulOffsetInByte;<BR><BR>&nbsp; &nbsp;ulByteBoundary = 
            ulBitOffset&gt;&gt;3 ;<BR>&nbsp; &nbsp;ulOffsetInByte = 
            ulBitOffset&amp;7;<BR><BR>&nbsp; &nbsp;*(pBuffer+ulByteBoundary) 
            &amp;= 
            (~(1&lt;&lt;ulOffsetInByte));<BR>}<BR><BR>ULONG<BR>ReadBitFromBitStream(<BR>&nbsp; 
            &nbsp;PUCHAR &nbsp;pBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulBitOffset<BR>&nbsp; &nbsp;)<BR>{<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulByteBoundary;<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulOffsetInByte;<BR><BR>&nbsp; &nbsp;ulByteBoundary = 
            ulBitOffset&gt;&gt;3 ;<BR>&nbsp; &nbsp;ulOffsetInByte = 
            ulBitOffset&amp;7;<BR><BR>&nbsp; &nbsp;return 
            ((*(PULONG)(pBuffer+ulByteBoundary))&gt;&gt;ulOffsetInByte)&amp;1 
            ;<BR>}<BR><BR><BR>ULONG WINAPI<BR>WriteGolombCode(<BR>&nbsp; 
            &nbsp;ULONG &nbsp; x,<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp;pBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; ulBitOffset<BR>&nbsp; 
            &nbsp;)<BR>{<BR>&nbsp; &nbsp;ULONG &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; q, r;<BR>&nbsp; &nbsp;int &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; i;<BR><BR>&nbsp; &nbsp;q = (x-1)&gt;&gt;m;<BR>&nbsp; &nbsp;r 
            = x-(q&lt;&lt;m)-1;<BR><BR>&nbsp; &nbsp;for(i=0; (ULONG)i&lt;q; i++, 
            ulBitOffset++)<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;Write1ToBitStream(pBuffer, ulBitOffset);<BR>&nbsp; 
            &nbsp;}<BR>&nbsp; &nbsp;Write0ToBitStream(pBuffer, 
            ulBitOffset);<BR>&nbsp; &nbsp;ulBitOffset++;<BR><BR>&nbsp; 
            &nbsp;for(i=0; i&lt;m; i++, ulBitOffset++)<BR>&nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;if( (r&gt;&gt;i)&amp;1 
            )<BR>&nbsp; &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;Write1ToBitStream(pBuffer, ulBitOffset);<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp;else<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;Write0ToBitStream(pBuffer, ulBitOffset);<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;}<BR>&nbsp; &nbsp;}<BR><BR>&nbsp; &nbsp;return 
            m+q+1;<BR>}<BR><BR><BR>ULONG<BR>ReadGolombCode(<BR>&nbsp; 
            &nbsp;PULONG &nbsp;pulCodingLength,<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp;pBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; ulBitOffset<BR>&nbsp; 
            &nbsp;)<BR>{<BR>&nbsp; &nbsp;ULONG &nbsp; q, r;<BR>&nbsp; 
            &nbsp;ULONG &nbsp; bit;<BR>&nbsp; &nbsp;int i;<BR><BR>&nbsp; 
            &nbsp;for(q=0; ;q++)<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;bit = (ULONG)ReadBitFromBitStream(pBuffer, 
            ulBitOffset);<BR>&nbsp; &nbsp; &nbsp; &nbsp;ulBitOffset++;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;if( !bit )<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;}<BR>&nbsp; &nbsp;}<BR><BR><BR>&nbsp; 
            &nbsp;for(i=0, r=0; (ULONG)i&lt;m; i++, ulBitOffset++)<BR>&nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;bit = 

⌨️ 快捷键说明

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