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

📄 huffmancodingclass.html

📁 本程序包用标准C++实现了Huffman编码以及解码的基本类
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0095)http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=HandyHuffmanCoding%2Fcpp6%2F3%2F2004 -->
<!-- HTML for article "Huffman Coding Class" by handychang,handychang
     URL: http://www.codeproject.com/cpp/HandyHuffmanCoding.asp

     Article content copyright handychang,handychang
     All formatting, additions and alterations Copyright ?CodeProject, 1999-2004
--><!----------------------------- Ignore -----------------------------><HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312"><LINK 
href="HuffmanCodingClass.files/global.css" type=text/css rel=stylesheet>
<META content="MSHTML 6.00.2800.1400" name=GENERATOR></HEAD>
<BODY>
<HR noShade SIZE=1>
<!----------------------------- Ignore -----------------------------><!----------------------------- Article Starts ----------------------------->

<H2>Contents</H2>
<UL>
  <LI><A 
  href="http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=HandyHuffmanCoding%2Fcpp6%2F3%2F2004#Introduction">Introduction</A> 

  <LI><A 
  href="http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=HandyHuffmanCoding%2Fcpp6%2F3%2F2004#Usingthecode">Using 
  the code</A> 
  <LI><A 
  href="http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=HandyHuffmanCoding%2Fcpp6%2F3%2F2004#ClassMembers">Class 
  Members</A> 
  <LI><A 
  href="http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=HandyHuffmanCoding%2Fcpp6%2F3%2F2004#Thanksto">Thanks 
  to...</A> 
  <LI><A 
  href="http://www.codeproject.com/script/Submit/ViewHTML.asp?guid=HandyHuffmanCoding%2Fcpp6%2F3%2F2004#Contact">Contacting 
  the Authors</A> </LI></UL>
<H2>Introduction<A name=Introduction></A></H2>
<P>This version of file encoder and decoder program is based on the Huffman 
coding method. It explicitly demonstrates the details of the files during the 
encoding and decoding. The algorithm is encapsulated in a class 
<CODE>En_Decode</CODE> by the standard C++ language. Here is a demonstration 
project for the class.</P>
<H2>Using the code<A name=Usingthecode></A></H2>
<P>This class is implemented by standard C++, so it is very easy to use.</P>
<OL>
  <LI>Create an MFC application program as usual. 
  <LI>Add the source file En_Decode.cpp and En_Decode.h to the project. 
  <LI>Add the header file to your project by: <PRE>//
//    #include "En_Decode.h"
//
</PRE>
  <P>Define your own coder object, such as:</P><PRE>//
//    En_Decode Coder;
//
</PRE>
  <LI>Use the member function of the class to set the source file name and 
  destination encoded file name, then call <CODE>Encode()</CODE> to encode the 
  source file. <PRE>//
//    Coder.SetInputFileName("C:/test.txt", "txt");
//    Coder.SetOutputFileName("C:/encoded");
//    Coder.Encode();
//
</PRE></LI></OL>
<P>In the same way, we can decode the encoded files to exactly the source 
file.</P>
<H2><A name=ClassMembers>Class Members</A></H2>
<H4>Construction</H4>
<TABLE cols=2 border=1>
  <TBODY>
  <TR vAlign=top>
    <TD width="29%"><CODE>En_Decode</CODE></A></TD>
    <TD width="71%">Constructs a <CODE>En_Decode</CODE> 
object.</TD></TR></TBODY></TABLE>
<H4>File Name Functions</H4>
<TABLE cols=2 border=1>
  <TBODY>
  <TR vAlign=top>
    <TD width="29%"><CODE>SetInputFileName</CODE></TD>
    <TD width="71%">Set the input file name.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>SetOutputFileName</CODE></TD>
    <TD width="71%">Set the output file name.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetExtName</CODE></TD>
    <TD width="71%">Get the ext name of the encoded file when 
  decoding.</TD></TR></TBODY></TABLE>
<H4>Paraneter Functions</H4>
<TABLE cols=2 border=1>
  <TBODY>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetMinFreq</CODE></TD>
    <TD width="71%">Get the minimum frequency of the symbols in the source 
      file.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetMaxFreq</CODE></TD>
    <TD width="71%">Get the maximum frequency of the symbols in the source 
      file.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetFreq(idx)</CODE></TD>
    <TD width="71%">Get the frequency value of a symbol in the source 
  file.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetActiveSymbols</CODE></TD>
    <TD width="71%">Get the number of active symbols in the source file.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetActualDataLength</CODE></TD>
    <TD width="71%">Get the bytes number of the encoded file not including 
      head.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetUncodedFileLength</CODE></TD>
    <TD width="71%">Get the length of the source file.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetEncodedFileCodeLength</CODE></TD>
    <TD width="71%">Get the average code length of the encoded file.</TD></TR>
  <TR vAlign=top>
    <TD width="29%"><CODE>GetSourceFileEntropy</CODE></TD>
    <TD width="71%">Get the entropy of the source file.</TD></TR></TBODY></TABLE>
<H2>Thanks to...<A name=Thanksto></A></H2>
<P>Derek Lakin for his help with <CODE>CTabCtrlSSL </CODE>in the demo 
project.</P>
<H2>Contacting the Authors<A name=Contact></A></H2>
<P>This is the first time I share my code here. It is done in a hurry, so 
exception handling is ignored. Any one who is interested in it can enhance it 
freely, and please let me know about any improvement, thanks!</P>
<P>I am a junior student in Huangzhong University of Science and Technology, 
China. I am interested in C++ and MFC, and any coding project. I am glad to 
share my codes here with any one, though it is not that good. </P>
<P>Please contact me via email (zxt0123@163.com).</P><!----------------------------- Article Ends -----------------------------></BODY></HTML>

⌨️ 快捷键说明

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