📄 qccenthuffmandesign.3
字号:
.TH QCCENTHUFFMANDESIGN 3 "QCCPACK" "".SH NAMEQccENTHuffmanDesign \-design of Huffman code table from probability distribution.SH SYNOPSIS.B #include "libQccPack.h".sp.BI "int QccENTHuffmanDesign(const int *" symbols ", const double *" probabilities ", int " num_symbols ", QccENTHuffmanTable *" huffman_table );.SH DESCRIPTION.BR QccENTHuffmanDesign()designs a Huffman code table for the alphabet ofsymbols given in.I symbolsand their associated.I probabilitiesof occurrence..I num_symbolsgives the number of symbols in the alphabet.The symbols themselves must be nonnegative integers less than orequal to.BR QCCENTHUFFMAN_MAXSYMBOL (currently,.BR QCCENTHUFFMAN_MAXSYMBOLis defined to be 100000).The.I probabilitiesare nonnegative doublesless than 1; the sum of all the probabilities should be equal to 1.0..LP.BR QccENTHuffmanDesign()can create a Huffman code table suitable for decoding or encodingusing the functions.BR QccENTHuffmanEncode (3)and.BR QccENTHuffmanDecode (3),respectively.For an encoding table,.IR huffman_table -> table_typeshould be set to.BR QCCENTHUFFMAN_ENCODETABLEbefore calling.BR QccENTHuffmanDesign() .For a decoding table,.IR huffman_table -> table_typeshould be set to.BR QCCENTHUFFMAN_DECODETABLEbefore calling.BR QccENTHuffmanDesign() ..LP.BR QccENTHuffmanDesign()will allocate space for the Huffman code table via a call to.BR QccENTHuffmanTableAlloc (3)so this does not need to be done in advance..LPAny of the symbolswhich have zero probabilitiesare not included in the output Huffman code table.That is, such zero-probability symbols are not included inthe building of the Huffman code tree, are therefore donot get Huffman codewords assigned to them..LPThe design algorithm employed by.BR QccENTHuffmanDesign()is essentially identical to the tree-basedtechnique described in Huffman's original paper.In order to keep the implementations of encoding and decodingpractical, the length of Huffman codewords has been limited to.BR QCCENTHUFFMAN_MAXCODEWORDLEN(31 bits) in this implementation.Unfortunately, Huffman's original algorithm cannot predict thelength of the longest codeword in advance of designing the code tree,nor can it place an upper bound on codeword lengths.As a result,.BR QccENTHuffmanDesign()will fail if, while designing the Huffman code, it encounters asituation that requires a codeword of length longer than.BR QCCENTHUFFMAN_MAXCODEWORDLENbits; this problem often arises when the symbol alphabet contains alarge number of symbols that have relatively small probabilities.In such a case, attempts to generate the code table areterminated, and a return value of 1 is returned to the callingprocedure..LPIt would probably be better to have the implementation resort to amodified Huffman code (i.e., a code in which low-probability symbolsare "collapsed" into a single node in the code tree, and a Hufffman-codeprefix along with a fixed-length code is used for the collapsed symbols)if a Huffman code cannot be builtwithout exceeding.BR QCCENTHUFFMAN_MAXCODEWORDLENcodeword length.This has not be done in this implementation, however..SH "RETURN VALUE"These routines return 0 on success, and 1 on failure..SH "SEE ALSO".BR QccENTHuffmanEncode (3),.BR QccENTHuffmanDecode (3),.BR QccENTHuffmanTable (3),.BR QccPackENT (3),.BR QccPack (3).LPD. A. Huffman, "A Method for the Construction of Minimum-Redundancy Codes,".IR "Proceedings of the IRE" ,vol. 40, pp. 1098-1101, September 1952..SH AUTHORCopyright (C) 1997-2009 James E. Fowler.\" The programs herein are free software; you can redistribute them an.or.\" modify them under the terms of the GNU General Public License.\" as published by the Free Software Foundation; either version 2.\" of the License, or (at your option) any later version..\" .\" These programs are distributed in the hope that they will be useful,.\" but WITHOUT ANY WARRANTY; without even the implied warranty of.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the.\" GNU General Public License for more details..\" .\" You should have received a copy of the GNU General Public License.\" along with these programs; if not, write to the Free Software.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -