\hypertarget{HUFF_8c}{
\section{HUFF.c File Reference}
\label{HUFF_8c}\index{HUFF.c@{HUFF.c}}
}
Huffman Encode/Decode, implementation file. 

{\tt \#include \char`\"{}LDT/HUFF.h\char`\"{}}\par
{\tt \#include \char`\"{}LDT/\_\-HUFF.dox\char`\"{}}\par
{\tt \#include \char`\"{}LDT/BFU.h\char`\"{}}\par
{\tt \#include \char`\"{}PBI/Alias.h\char`\"{}}\par
{\tt \#include \char`\"{}ffs.h\char`\"{}}\par
{\tt \#include \char`\"{}dprintf.h\char`\"{}}\par
{\tt \#include $<$limits.h$>$}\par
{\tt \#include $<$stdlib.h$>$}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$stdio.h$>$}\par


Include dependency graph for HUFF.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=239pt]{HUFF_8c__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct {\bf \_\-HUFF\_\-dinfo\_\-bf}
\item 
struct \hyperlink{union__HUFF__dinfo}{\_\-HUFF\_\-dinfo}
\begin{CompactList}\small\item\em The information associate with a list member. \item\end{CompactList}\item 
struct \hyperlink{struct__HUFF__dlist}{\_\-HUFF\_\-dlist}
\begin{CompactList}\small\item\em Structure associated with each symbol length. \item\end{CompactList}\item 
struct \hyperlink{struct__HUFF__dtable}{\_\-HUFF\_\-dtable}
\begin{CompactList}\small\item\em Template of a huffman decoding table. \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{HUFF_8c_a0}{
\#define {\bf title\_\-bar\_\-print}()}
\label{HUFF_8c_a0}

\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{HUFF_8c_a1}{
typedef int($\ast$ {\bf assign\_\-rtn} )(\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$cnts, const unsigned int $\ast$parent, const unsigned int $\ast$valid, int cnt)}
\label{HUFF_8c_a1}

\item 
\hypertarget{HUFF_8c_a2}{
typedef \_\-HUFF\_\-dinfo\_\-bf {\bf HUFF\_\-dinfo\_\-bf}}
\label{HUFF_8c_a2}

\item 
\hypertarget{HUFF_8c_a3}{
typedef \hyperlink{union__HUFF__dinfo}{\_\-HUFF\_\-dinfo} {\bf HUFF\_\-dinfo}}
\label{HUFF_8c_a3}

\item 
\hypertarget{HUFF_8c_a4}{
typedef \hyperlink{struct__HUFF__dlist}{\_\-HUFF\_\-dlist} \hyperlink{HUFF_8c_a4}{HUFF\_\-dlist}}
\label{HUFF_8c_a4}

\begin{CompactList}\small\item\em Typedef for struct \hyperlink{struct__HUFF__dlist}{\_\-HUFF\_\-dlist}. \item\end{CompactList}\item 
\hypertarget{HUFF_8c_a5}{
typedef \hyperlink{struct__HUFF__dtable}{\_\-HUFF\_\-dtable} {\bf HUFF\_\-dtable}}
\label{HUFF_8c_a5}

\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static int \hyperlink{HUFF_8c_a6}{heap\_\-construct} (const unsigned int $\ast$$\ast$heap, const unsigned int $\ast$freq, const unsigned int $\ast$valid, int cnt, unsigned int $\ast$freq\_\-max)
\begin{CompactList}\small\item\em Constructs the heap used to maintain the sorted array of frequency counts. \item\end{CompactList}\item 
static \_\-\_\-inline void \hyperlink{HUFF_8c_a7}{heap\_\-down} (const unsigned int $\ast$$\ast$heap, int n, int k)
\begin{CompactList}\small\item\em Local implementation to push a new count, indexed by k, on to the heap. \item\end{CompactList}\item 
\hypertarget{HUFF_8c_a8}{
static void {\bf make} (const unsigned int $\ast$$\ast$heap, const unsigned int $\ast$freqs, int n, unsigned int $\ast$counts, int k, unsigned int $\ast$parent)}
\label{HUFF_8c_a8}

\item 
static int \hyperlink{HUFF_8c_a9}{build} (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$freq, const unsigned int $\ast$valid, int nvalid, unsigned int $\ast$wa, assign\_\-rtn assign)
\begin{CompactList}\small\item\em Constructs the Huffman codes for the specified frequency distribution. \item\end{CompactList}\item 
static int \hyperlink{HUFF_8c_a10}{assign\_\-dense} (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$counts, const unsigned int $\ast$parents, const unsigned int $\ast$valid, int cnt)
\begin{CompactList}\small\item\em Assigns the codes to a dense code array. \item\end{CompactList}\item 
static int \hyperlink{HUFF_8c_a11}{assign\_\-sparse} (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$counts, const unsigned int $\ast$parents, const unsigned int $\ast$valid, int cnt)
\begin{CompactList}\small\item\em Assign the codes to a sparse code array. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a12}{HUFF\_\-build} (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$freq, int cnt, unsigned int $\ast$wa)
\begin{CompactList}\small\item\em Builds the code table directly from the specified frequency array. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a13}{HUFF\_\-build\-Dense} (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$freq, const unsigned int $\ast$valid, int nvalid, unsigned int $\ast$wa)
\begin{CompactList}\small\item\em Builds a dense list, that is the resulting code list is indexed in a space that is dense in the valid element numbering scheme. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a14}{HUFF\_\-build\-Sparse} (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$freq, const unsigned int $\ast$valid, int nvalid, unsigned int $\ast$wa)
\begin{CompactList}\small\item\em Builds a sparse code list. That is the resulting code list is indexed in the same manner as the {\em frequency\/} array. Contrast this with HUFF\_\-build\-Dense, where the resulting code list is indexed in the same manner as the {\em valid\/} array. Note that because the non-valid elements are not filled in, it is the caller's responsibility to avoid accessing these elements. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{HUFF_8c_a15}{calc\_\-len} (const unsigned int $\ast$parents, int k)
\begin{CompactList}\small\item\em Calculates the length for the tree starting at {\em parent\/}. \item\end{CompactList}\item 
\hypertarget{HUFF_8c_a16}{
static \_\-\_\-inline void {\bf calc\_\-start\_\-patterns} (unsigned int $\ast$start, const unsigned int $\ast$lengths, unsigned int max)}
\label{HUFF_8c_a16}

\item 
\hypertarget{HUFF_8c_a17}{
static \_\-\_\-inline \hyperlink{struct__HUFF__code}{HUFF\_\-code} {\bf assign\_\-code} (unsigned int len, unsigned int $\ast$start)}
\label{HUFF_8c_a17}

\item 
int \hyperlink{HUFF_8c_a18}{HUFF\_\-bcompress} (void $\ast$out, unsigned int boff, void $\ast$max, const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned char $\ast$in, int cnt, int $\ast$unencoded)
\begin{CompactList}\small\item\em Convenience routine to compress a byte stream. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a19}{HUFF\_\-size} (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$freqs, int count)
\begin{CompactList}\small\item\em Computes the size, in bits, of the specified encode {\em freqs\/}. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a20}{HUFF\_\-size\-Dense} (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$freq, const unsigned int $\ast$valid, int nvalid)
\begin{CompactList}\small\item\em Sizes the given frequency array using the specified code list. the code list is a dense list of the valid members. The valid members are specified either by the non-zero elements in the frequency array or the {\em valid\/} array. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a21}{HUFF\_\-size\-Sparse} (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$freq, const unsigned int $\ast$valid, int nvalid)
\begin{CompactList}\small\item\em Sizes the given frequency array using the specified code list. the code list is a sparse list of the valid members. The valid members are specified either by the non-zero elements in the frequency array or the {\em valid\/} array. \item\end{CompactList}\item 
\hypertarget{HUFF_8c_a22}{
{\bf ALIAS\_\-FNC} (unsigned int, HUFF\_\-decompress\-Bytes, HUFF\_\-bdecompress)}
\label{HUFF_8c_a22}

\item 
int \hyperlink{HUFF_8c_a23}{HUFF\_\-dtable\-Sizeof} (int nsymbols)
\begin{CompactList}\small\item\em Returns the size, in bytes, of the decoding table needed for the specified number of symbols. \item\end{CompactList}\item 
void \hyperlink{HUFF_8c_a24}{HUFF\_\-dtable\-Build} (\hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable, const unsigned char $\ast$sym\_\-lens, int nsym\_\-lens)
\begin{CompactList}\small\item\em Construct a decoding table based on the lengths of symbols This constructs the huffman codes in the canonical form. \item\end{CompactList}\item 
void \hyperlink{HUFF_8c_a25}{HUFF\_\-dtable\-Biase} (\hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable, int biase)
\begin{CompactList}\small\item\em Biases a previously constructed table by the amount specified. That is, an unbiased symbol value of 0, will be biased to the value specified by {\em biase\/}. \item\end{CompactList}\item 
static \_\-\_\-inline unsigned int \hyperlink{HUFF_8c_a26}{decode} (unsigned int present, unsigned int max, const \hyperlink{struct__HUFF__dlist}{HUFF\_\-dlist} $\ast$offsets, unsigned int bs)
\begin{CompactList}\small\item\em Decodes one symbol from the input bit string. \item\end{CompactList}\item 
unsigned int \hyperlink{HUFF_8c_a27}{HUFF\_\-decode} (const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable, const unsigned int $\ast$src, unsigned int boff)
\begin{CompactList}\small\item\em Decodes one symbol from the input bit source. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a28}{HUFF\_\-decompress\-Bytes} (unsigned char $\ast$dst, int cnt, const void $\ast$src, unsigned int boff, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable)
\begin{CompactList}\small\item\em Convenience routine to decode a bit stream using the specified table into a byte array. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a29}{HUFF\_\-decompress\-Shorts} (unsigned short int $\ast$dst, int cnt, const void $\ast$src, unsigned int boff, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable)
\begin{CompactList}\small\item\em Convenience routine to decode a bit stream using the specified table into a unsigned short array. \item\end{CompactList}\item 
int \hyperlink{HUFF_8c_a30}{HUFF\_\-decompress\-Longs} (unsigned int $\ast$dst, int cnt, const void $\ast$src, unsigned int boff, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable)
\begin{CompactList}\small\item\em Convenience routine to decode a bit stream using the specified table into a unsigned short array. \item\end{CompactList}\item 
static \_\-\_\-inline int \hyperlink{HUFF_8c_a31}{is\_\-valid} (int idx, const unsigned int $\ast$valid, int nvalid)
\begin{CompactList}\small\item\em Determines whether the index {\em idx\/} is a member of the valid set of indices. \item\end{CompactList}\item 
void \hyperlink{HUFF_8c_a32}{HUFF\_\-codes\-Print} (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, int ncodes)
\begin{CompactList}\small\item\em Prints an ASCII display of the specified {\em codes\/}. \item\end{CompactList}\item 
void \hyperlink{HUFF_8c_a33}{HUFF\_\-codes\-Print\-Dense} (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$valid, int nvalid)
\begin{CompactList}\small\item\em Prints an ASCII display of the specified {\em codes\/}. The codes are assumed to be\begin{enumerate}
\item densely packed in the {\em codes\/} array,\item in the same order as the {\em valid\/} array and\item that there are {\em nvalid\/} codes. \end{enumerate}
\item\end{CompactList}\item 
void \hyperlink{HUFF_8c_a34}{HUFF\_\-codes\-Print\-Sparse} (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$codes, const unsigned int $\ast$valid, int nvalid)
\begin{CompactList}\small\item\em Prints an ASCII display of the specified {\em codes\/}. The {\em valid\/} arrays contains the list of indices that will be printed. \item\end{CompactList}\item 
static \_\-\_\-inline int \hyperlink{HUFF_8c_a35}{ndigits\_\-compute} (unsigned int value)
\begin{CompactList}\small\item\em Calculate the number of decimal digits in {\em value\/}. \item\end{CompactList}\item 
void \hyperlink{HUFF_8c_a36}{HUFF\_\-dtable\-Print} (const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable)
\begin{CompactList}\small\item\em Provides an ASCII display of the decoding table. This is usually for debugging or diagnostic purposes. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Huffman Encode/Decode, implementation file. 

\begin{Desc}
\item[Author:]JJRussell - \href{mailto:russell@slac.stanford.edu}{\tt russell@slac.stanford.edu}\end{Desc}


\footnotesize\begin{verbatim}CVS $Id
\end{verbatim}
\normalsize


The main documentation for this implementation of the huffman encoding and decoding is kept in \hyperlink{__HUFF_8dox}{\_\-HUFF.dox}

\subsection{Function Documentation}
\hypertarget{HUFF_8c_a10}{
\index{HUFF.c@{HUFF.c}!assign_dense@{assign\_\-dense}}
\index{assign_dense@{assign\_\-dense}!HUFF.c@{HUFF.c}}
\subsubsection[assign\_\-dense]{\setlength{\rightskip}{0pt plus 5cm}static int assign\_\-dense (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em counts}, const unsigned int $\ast$ {\em parents}, const unsigned int $\ast$ {\em valid}, int {\em cnt})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a10}


Assigns the codes to a dense code array. 

\begin{Desc}
\item[Returns:]The number of elements populated in the code array.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code array to be populated \item[{\em counts}]The sparse array of counts \item[{\em parents}]The parent array \item[{\em valid}]The indices of the valid elements \item[{\em cnt}]The number of elements in the counts array\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a11}{
\index{HUFF.c@{HUFF.c}!assign_sparse@{assign\_\-sparse}}
\index{assign_sparse@{assign\_\-sparse}!HUFF.c@{HUFF.c}}
\subsubsection[assign\_\-sparse]{\setlength{\rightskip}{0pt plus 5cm}static int assign\_\-sparse (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em counts}, const unsigned int $\ast$ {\em parents}, const unsigned int $\ast$ {\em valid}, int {\em cnt})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a11}


Assign the codes to a sparse code array. 

\begin{Desc}
\item[Returns:]The number of elements populated in the code array.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code array to be populated \item[{\em counts}]The sparse array of counts \item[{\em parents}]The parent array \item[{\em valid}]If non-zero, the indices of the valid members \item[{\em cnt}]The number of elements in the counts array\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a9}{
\index{HUFF.c@{HUFF.c}!build@{build}}
\index{build@{build}!HUFF.c@{HUFF.c}}
\subsubsection[build]{\setlength{\rightskip}{0pt plus 5cm}static int build (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em freqs}, const unsigned int $\ast$ {\em valid}, int {\em nvalid}, unsigned int $\ast$ {\em wa}, assign\_\-rtn {\em assign})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a9}


Constructs the Huffman codes for the specified frequency distribution. 

\begin{Desc}
\item[Returns:]The number of code elements used in the code array.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code table to be populated. The elements acutally populated by the code building routine.\item[{\em freqs}]The frequency table.\item[{\em valid}]An array of {\em nvalid\/} elements, giving the indices of the valid elements in the frequency array. This may be specified as NULL, in which case, {\em nvalid\/} gives the number of elements in the frequency table.\item[{\em nvalid}]The number of entries in the valid table. If {\em valid\/} is specified as NULL, then this value must be the total number elements in the {\em freq\/} array.\item[{\em wa}]A temporary work area of size with at least HUFF\_\-N\_\-WA({\em nvalid\/}) elements available. For documentation and planning purposes, this is 2 $\ast$ number of valid elements, where the number of valid elements is either\begin{itemize}
\item {\em nvalid\/}, if {\em valid\/} is specified as non-NULL\item the number of non-0 entries, if {\em valid\/} is specified as NULL. \end{itemize}
\end{description}
\end{Desc}
\begin{Desc}
\item[]To keep your code compile-time safe, please use the macros.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em assign}]Callback routine to assign the code lengths\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a15}{
\index{HUFF.c@{HUFF.c}!calc_len@{calc\_\-len}}
\index{calc_len@{calc\_\-len}!HUFF.c@{HUFF.c}}
\subsubsection[calc\_\-len]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline unsigned int calc\_\-len (const unsigned int $\ast$ {\em parents}, int {\em k})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a15}


Calculates the length for the tree starting at {\em parent\/}. 

\begin{Desc}
\item[Returns:]The length of the tree starting at {\em parent\/} \end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em parents}]The tree to traverse \item[{\em k}]The starting position in the tree\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a26}{
\index{HUFF.c@{HUFF.c}!decode@{decode}}
\index{decode@{decode}!HUFF.c@{HUFF.c}}
\subsubsection[decode]{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-inline unsigned int decode (unsigned int {\em present}, unsigned int {\em max}, const \hyperlink{struct__HUFF__dlist}{HUFF\_\-dlist} $\ast$ {\em offsets}, unsigned int {\em bs})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a26}


Decodes one symbol from the input bit string. 

\begin{Desc}
\item[Returns:]A descriptor of the decoded symbol. This contains the symbol value and the number of bits consumed from the bit string\end{Desc}
\hypertarget{HUFF_8c_a6}{
\index{HUFF.c@{HUFF.c}!heap_construct@{heap\_\-construct}}
\index{heap_construct@{heap\_\-construct}!HUFF.c@{HUFF.c}}
\subsubsection[heap\_\-construct]{\setlength{\rightskip}{0pt plus 5cm}static int heap\_\-construct (const unsigned int $\ast$$\ast$ {\em heap}, const unsigned int $\ast$ {\em freq}, const unsigned int $\ast$ {\em valid}, int {\em cnt}, unsigned int $\ast$ {\em freq\_\-max})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a6}


Constructs the heap used to maintain the sorted array of frequency counts. 

\begin{Desc}
\item[Returns:]The number of valid elements currently on the heap. This is, at most, cnt. The full heap needs one more element to handle the sum of two elements.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em heap}]The storage for the indirect heap \item[{\em freq}]The frequency distribution \item[{\em valid}]The array of valid entries (optional, may be specified as NULL, in which case only non-zero entries will be treated as valid \item[{\em cnt}]The count number of\begin{itemize}
\item If {\em valid\/} is NULL, the number of entries in the the frequency array, {\em freq\/} \item If {\em valid\/} is non-NULL, the number of entries in the valid array, {\em valid\/}. \end{itemize}
\item[{\em freq\_\-max}]Returned as the pointer to the element holding the last frequency entry. This is used to distinguish elements in the heap that are from the original frequency distribution from the derived distribution when combining entries.\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a7}{
\index{HUFF.c@{HUFF.c}!heap_down@{heap\_\-down}}
\index{heap_down@{heap\_\-down}!HUFF.c@{HUFF.c}}
\subsubsection[heap\_\-down]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline void heap\_\-down (const unsigned int $\ast$$\ast$ {\em heap}, int {\em n}, int {\em k})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a7}


Local implementation to push a new count, indexed by k, on to the heap. 

printf (\char`\"{}heapj0\mbox{[}\%3u\mbox{]} = \%8u, cnts = \%8u$\backslash$n\char`\"{}, j, hj, cj);

printf (\char`\"{}heapj1\mbox{[}\%3u\mbox{]} = \%8u, cnts = \%8u$\backslash$n\char`\"{}, j+1, hj1, cj1);

printf (\char`\"{}heapk0\mbox{[}\%3u\mbox{]} = \%8u, cnts = \%8u DONE$\backslash$n\char`\"{}, j, hj); \hypertarget{HUFF_8c_a18}{
\index{HUFF.c@{HUFF.c}!HUFF_bcompress@{HUFF\_\-bcompress}}
\index{HUFF_bcompress@{HUFF\_\-bcompress}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-bcompress]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-bcompress (void $\ast$ {\em out}, unsigned int {\em boff}, void $\ast$ {\em max}, const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned char $\ast$ {\em in}, int {\em cnt}, int $\ast$ {\em unencoded})}}
\label{HUFF_8c_a18}


Convenience routine to compress a byte stream. 

\begin{Desc}
\item[Returns:]The number of bits needed to encoded the byte stream. If negative the all the symbols could not be encoded and {\em unencoded\/} should be checked for the count of those symbols not encoded. This number will represent negative the number of bits used to encode the symbols that would fit.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em out}]The output buffer \item[{\em boff}]The current bit offset \item[{\em max}]The maximum output address (actually 1 byte past it) \item[{\em codes}]The array of codes \item[{\em in}]The input buffer of symbols. \item[{\em cnt}]The number of input symbols. \item[{\em unencoded}]The number of input symbols left to encode. If successful this will be 0.\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a12}{
\index{HUFF.c@{HUFF.c}!HUFF_build@{HUFF\_\-build}}
\index{HUFF_build@{HUFF\_\-build}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-build]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-build (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em freq}, int {\em cnt}, unsigned int $\ast$ {\em wa})}}
\label{HUFF_8c_a12}


Builds the code table directly from the specified frequency array. 

\begin{Desc}
\item[Returns:]The number of valid codes. If this number $<$= 1, no valid code array exist. This happens if the input distribution has only 0 or 1 valid entries. Such a distribution has 0 entropy, and, therefore, needs no bits to encode.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code table to be populated.\item[{\em freq}]The frequency table.\item[{\em cnt}]The number of entries in the frequency table and, by implication, the code table.\item[{\em wa}]A temporary work area of size with at least \hyperlink{HUFF_8h_a0}{HUFF\_\-N\_\-WA(nvalid)} elements available where nvalid is the number of non-zero entries in the frequency table. For documentation and planning purposes, this is 2 $\ast$ nvalid elements. To keep your code compile-time safe, please use the macro.\end{description}
\end{Desc}
\begin{Desc}
\item[Note:]Any 0 count elements in the frequency table will be considered to be invalid. While the code array will be dimensioned from 0 ot {\em cnt\/}, only those elements that correspond to non-zero elements in the frequency table will have valid entries. If the user wishes to fill these code values with 0, he may do so, but only {\em after\/} the codes have been filled in. (This routine reserves the right to use the code array as a temporary working area in order to decrease memory requirements.\end{Desc}
\begin{Desc}
\item[]If one has an array that gives the valid elements, consider using HUFF\_\-build\-Sparse. If has a reverse lookup table, (i.e. an array that gives an index that is dense in the valid element number space, consider using HUFF\_\-build\-Dense. This will produce a table that number in the dense space of only valid elements. Doing this can save a lookup during the encoding process.\end{Desc}
\begin{Desc}
\item[]Typical usage would be\end{Desc}


\footnotesize\begin{verbatim}  //
  // If some elements of the frequency array are 0, the working area
  // may be dimensioned smaller, however, by specifying the maximum 
  // possible, one can do this a compile-time, avoiding run-time 
  // allocations.
  //
  int        freq[30];
  HUFF_code codes[30];
  int          wa[HUFF_N_WA(30)];

  accumulate (freqs, ....);
  dcnt = HUFF_build (codes, freq, 30, wa);
\end{verbatim}
\normalsize
\hypertarget{HUFF_8c_a13}{
\index{HUFF.c@{HUFF.c}!HUFF_buildDense@{HUFF\_\-buildDense}}
\index{HUFF_buildDense@{HUFF\_\-buildDense}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-buildDense]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-build\-Dense (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em freq}, const unsigned int $\ast$ {\em valid}, int {\em nvalid}, unsigned int $\ast$ {\em wa})}}
\label{HUFF_8c_a13}


Builds a dense list, that is the resulting code list is indexed in a space that is dense in the valid element numbering scheme. 

\begin{Desc}
\item[Returns:]The number of elements populated in the code array. If {\em valid\/} \begin{itemize}
\item NULL, then 0 count elements in the frequency array are considered invalid, and the count of non-0 frequency elements is returned.\item non-NULL, then the return value will be {\em nvalid\/}.\end{itemize}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code table to be populated.\item[{\em freq}]The frequency table. This area generally contains the number of elements specified by {\em nvalid\/} or the largest index in {\em valid\/}.\item[{\em valid}]An array of {\em nvalid\/} elements, giving the indices of the valid elements in the frequency array. If this is specified as NULL, although no storage is actually used, this routine's behaviour is as if this array contained indices to only the non-zero elements. Note that, if specified, no element of {\em valid\/} may reference a 0 count element in the frequency table.\item[{\em nvalid}]The number of entries in the {\em valid\/} table. If {\em valid\/} if specified as NULL, then this is taken to be the number values in the frequency table.\item[{\em wa}]A temporary work area of size with at least HUFF\_\-N\_\-WA({\em nvalid\/}) elements available. For documentation and planning purposes, this is 2 $\ast$ {\em nvalid\/} elements. To keep your code compile-time safe, please use the macros. \end{description}
\end{Desc}
\begin{Desc}
\item[]See the examples in HUFF\_\-build, which are identical with the exception of adding the {\em valid\/} array argument.\end{Desc}
\hypertarget{HUFF_8c_a14}{
\index{HUFF.c@{HUFF.c}!HUFF_buildSparse@{HUFF\_\-buildSparse}}
\index{HUFF_buildSparse@{HUFF\_\-buildSparse}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-buildSparse]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-build\-Sparse (\hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em freq}, const unsigned int $\ast$ {\em valid}, int {\em nvalid}, unsigned int $\ast$ {\em wa})}}
\label{HUFF_8c_a14}


Builds a sparse code list. That is the resulting code list is indexed in the same manner as the {\em frequency\/} array. Contrast this with HUFF\_\-build\-Dense, where the resulting code list is indexed in the same manner as the {\em valid\/} array. Note that because the non-valid elements are not filled in, it is the caller's responsibility to avoid accessing these elements. 

\begin{Desc}
\item[Returns:]The number of valid elements in the code array. If {\em valid\/} is specified as\begin{itemize}
\item NULL, then this is the number of non-zero elements in the frequency array.\item non-NULL, then this is nvalid.\end{itemize}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code table to be populated. Only those elements indexed by the valid table are populated.\item[{\em freq}]The frequency table. This array must contains the number of elements specified by {\em nvalid\/} or, if {\em valid\/} is non-NULL, the largest index in {\em valid\/}.\item[{\em valid}]An array of {\em nvalid\/} elements, giving the indices of the valid elements in the frequency array. If this is specified as NULL, although no storage is actually used, this routine's behaviour is as if this array contained indices to only the non-zero elements.\item[{\em nvalid}]The number of entries in the valid table. If {\em valid\/} is specified as NULL, then this value must be the total number elements in the {\em freq\/} array.\item[{\em wa}]A temporary work area of size with at least HUFF\_\-N\_\-WA({\em nvalid\/}) elements available. For documentation and planning purposes, this is 2 $\ast${\em nvalid\/} elements. To keep your code compile-time safe, please use the macros. \end{description}
\end{Desc}
\begin{Desc}
\item[]See the examples in HUFF\_\-build, which are identical with the exception of adding the {\em valid\/} array argument\end{Desc}
\hypertarget{HUFF_8c_a32}{
\index{HUFF.c@{HUFF.c}!HUFF_codesPrint@{HUFF\_\-codesPrint}}
\index{HUFF_codesPrint@{HUFF\_\-codesPrint}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-codesPrint]{\setlength{\rightskip}{0pt plus 5cm}void HUFF\_\-codes\-Print (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, int {\em ncodes})}}
\label{HUFF_8c_a32}


Prints an ASCII display of the specified {\em codes\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The array of codes to print \item[{\em ncodes}]The number of codes to print\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a33}{
\index{HUFF.c@{HUFF.c}!HUFF_codesPrintDense@{HUFF\_\-codesPrintDense}}
\index{HUFF_codesPrintDense@{HUFF\_\-codesPrintDense}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-codesPrintDense]{\setlength{\rightskip}{0pt plus 5cm}void HUFF\_\-codes\-Print\-Dense (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em valid}, int {\em nvalid})}}
\label{HUFF_8c_a33}


Prints an ASCII display of the specified {\em codes\/}. The codes are assumed to be\begin{enumerate}
\item densely packed in the {\em codes\/} array,\item in the same order as the {\em valid\/} array and\item that there are {\em nvalid\/} codes. \end{enumerate}


\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The array of codes to print \item[{\em valid}]The array of valid indices \item[{\em nvalid}]The number of codes to print\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a34}{
\index{HUFF.c@{HUFF.c}!HUFF_codesPrintSparse@{HUFF\_\-codesPrintSparse}}
\index{HUFF_codesPrintSparse@{HUFF\_\-codesPrintSparse}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-codesPrintSparse]{\setlength{\rightskip}{0pt plus 5cm}void HUFF\_\-codes\-Print\-Sparse (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em valid}, int {\em nvalid})}}
\label{HUFF_8c_a34}


Prints an ASCII display of the specified {\em codes\/}. The {\em valid\/} arrays contains the list of indices that will be printed. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The array of codes to print \item[{\em valid}]List of valid codes \item[{\em nvalid}]the nubmer of valid indices\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a27}{
\index{HUFF.c@{HUFF.c}!HUFF_decode@{HUFF\_\-decode}}
\index{HUFF_decode@{HUFF\_\-decode}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-decode]{\setlength{\rightskip}{0pt plus 5cm}unsigned int HUFF\_\-decode (const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable}, const unsigned int $\ast$ {\em src}, unsigned int {\em boff})}}
\label{HUFF_8c_a27}


Decodes one symbol from the input bit source. 

\begin{Desc}
\item[Returns:]A descriptor of the decoded symbol consisting of the value and the number of bits consumed from the bit string\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dtable}]The decoding table \item[{\em src}]The source buffer \item[{\em boff}]The bit offset into the source buffer\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a28}{
\index{HUFF.c@{HUFF.c}!HUFF_decompressBytes@{HUFF\_\-decompressBytes}}
\index{HUFF_decompressBytes@{HUFF\_\-decompressBytes}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-decompressBytes]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-decompress\-Bytes (unsigned char $\ast$ {\em dst}, int {\em cnt}, const void $\ast$ {\em src}, unsigned int {\em boff}, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable})}}
\label{HUFF_8c_a28}


Convenience routine to decode a bit stream using the specified table into a byte array. 

\begin{Desc}
\item[Returns:]The number of bits that were decoded\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dst}]The destination/output buffer \item[{\em cnt}]The number of symbols to decode \item[{\em src}]The encoded source/input buffer \item[{\em boff}]The bit offset to start at in the input buffer \item[{\em dtable}]The decoding table\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a30}{
\index{HUFF.c@{HUFF.c}!HUFF_decompressLongs@{HUFF\_\-decompressLongs}}
\index{HUFF_decompressLongs@{HUFF\_\-decompressLongs}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-decompressLongs]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-decompress\-Longs (unsigned int $\ast$ {\em dst}, int {\em cnt}, const void $\ast$ {\em src}, unsigned int {\em boff}, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable})}}
\label{HUFF_8c_a30}


Convenience routine to decode a bit stream using the specified table into a unsigned short array. 

\begin{Desc}
\item[Returns:]The number of bits that were decoded\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dst}]The destination/output buffer \item[{\em cnt}]The number of symbols to decode \item[{\em src}]The encoded source/input buffer \item[{\em boff}]The bit offset to start at in the input buffer \item[{\em dtable}]The decoding table\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a29}{
\index{HUFF.c@{HUFF.c}!HUFF_decompressShorts@{HUFF\_\-decompressShorts}}
\index{HUFF_decompressShorts@{HUFF\_\-decompressShorts}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-decompressShorts]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-decompress\-Shorts (unsigned short int $\ast$ {\em dst}, int {\em cnt}, const void $\ast$ {\em src}, unsigned int {\em boff}, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable})}}
\label{HUFF_8c_a29}


Convenience routine to decode a bit stream using the specified table into a unsigned short array. 

\begin{Desc}
\item[Returns:]The number of bits that were decoded\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dst}]The destination/output buffer \item[{\em cnt}]The number of symbols to decode \item[{\em src}]The encoded source/input buffer \item[{\em boff}]The bit offset to start at in the input buffer \item[{\em dtable}]The decoding table\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a25}{
\index{HUFF.c@{HUFF.c}!HUFF_dtableBiase@{HUFF\_\-dtableBiase}}
\index{HUFF_dtableBiase@{HUFF\_\-dtableBiase}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-dtableBiase]{\setlength{\rightskip}{0pt plus 5cm}void HUFF\_\-dtable\-Biase (\hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable}, int {\em biase})}}
\label{HUFF_8c_a25}


Biases a previously constructed table by the amount specified. That is, an unbiased symbol value of 0, will be biased to the value specified by {\em biase\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dtable}]The decoding table to be built \item[{\em biase}]The biase value\end{description}
\end{Desc}
It is fairly common that the original symbols where encoded into a space from \mbox{[}0, nsymbols) from an original space \mbox{[}biase, nsymbols+biase). This routine allows the caller to reapply that biase so that the returned symbol value is in the original space, without looping over all the decoded symbols and reapplying the biase.\hypertarget{HUFF_8c_a24}{
\index{HUFF.c@{HUFF.c}!HUFF_dtableBuild@{HUFF\_\-dtableBuild}}
\index{HUFF_dtableBuild@{HUFF\_\-dtableBuild}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-dtableBuild]{\setlength{\rightskip}{0pt plus 5cm}void HUFF\_\-dtable\-Build (\hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable}, const unsigned char $\ast$ {\em sym\_\-lens}, int {\em nsym\_\-lens})}}
\label{HUFF_8c_a24}


Construct a decoding table based on the lengths of symbols This constructs the huffman codes in the canonical form. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dtable}]The decoding table to be built \item[{\em sym\_\-lens}]An array representing the lengths of each symbol \item[{\em nsym\_\-lens}]The number of symbol lengths\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a36}{
\index{HUFF.c@{HUFF.c}!HUFF_dtablePrint@{HUFF\_\-dtablePrint}}
\index{HUFF_dtablePrint@{HUFF\_\-dtablePrint}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-dtablePrint]{\setlength{\rightskip}{0pt plus 5cm}void HUFF\_\-dtable\-Print (const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable})}}
\label{HUFF_8c_a36}


Provides an ASCII display of the decoding table. This is usually for debugging or diagnostic purposes. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em dtable}]The decoding table to display\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a23}{
\index{HUFF.c@{HUFF.c}!HUFF_dtableSizeof@{HUFF\_\-dtableSizeof}}
\index{HUFF_dtableSizeof@{HUFF\_\-dtableSizeof}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-dtableSizeof]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-dtable\-Sizeof (int {\em nsymbols})}}
\label{HUFF_8c_a23}


Returns the size, in bytes, of the decoding table needed for the specified number of symbols. 

\begin{Desc}
\item[Returns:]The size, in bytes, of the decoding table needed for the specified number of symbols\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em nsymbols}]The number of symbols\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a19}{
\index{HUFF.c@{HUFF.c}!HUFF_size@{HUFF\_\-size}}
\index{HUFF_size@{HUFF\_\-size}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-size]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-size (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em freqs}, int {\em count})}}
\label{HUFF_8c_a19}


Computes the size, in bits, of the specified encode {\em freqs\/}. 

\begin{Desc}
\item[Returns:]The size in bits.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code table, must be {\em count\/} in length \item[{\em freqs}]The frequency distribution, must be {\em count\/} in length \item[{\em count}]The number of elements in the frequency distribution and the code table.\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a20}{
\index{HUFF.c@{HUFF.c}!HUFF_sizeDense@{HUFF\_\-sizeDense}}
\index{HUFF_sizeDense@{HUFF\_\-sizeDense}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-sizeDense]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-size\-Dense (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em freq}, const unsigned int $\ast$ {\em valid}, int {\em nvalid})}}
\label{HUFF_8c_a20}


Sizes the given frequency array using the specified code list. the code list is a dense list of the valid members. The valid members are specified either by the non-zero elements in the frequency array or the {\em valid\/} array. 

\begin{Desc}
\item[Returns:]The size, in bits, of the encoded distribution\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code table to use\item[{\em freq}]The frequency table.\end{description}
\end{Desc}
If {\em valid\/} array is non-zero, then this array is indexed by the validity array

If {\em valid\/} array is specified as NULL, then only the non-zero elements of {\em freq\/} are considered valid.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em valid}]An array of {\em nvalid\/} elements, giving the indices of the valid elements in the frequency array. This may be specified as NULL, in which case, only the non-zero elements of {\em freq\/} are considered valid and {\em nvalid\/} gives the length, not of the validity array, but of the frequency distribution.\item[{\em nvalid}]If {\em valid\/} is\begin{itemize}
\item Non-NULL, then this is the number of entries in the {\em valid\/} array.\par
\item NULL, then this is the number of elements in the frequency array.\end{itemize}
\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a21}{
\index{HUFF.c@{HUFF.c}!HUFF_sizeSparse@{HUFF\_\-sizeSparse}}
\index{HUFF_sizeSparse@{HUFF\_\-sizeSparse}!HUFF.c@{HUFF.c}}
\subsubsection[HUFF\_\-sizeSparse]{\setlength{\rightskip}{0pt plus 5cm}int HUFF\_\-size\-Sparse (const \hyperlink{struct__HUFF__code}{HUFF\_\-code} $\ast$ {\em codes}, const unsigned int $\ast$ {\em freq}, const unsigned int $\ast$ {\em valid}, int {\em nvalid})}}
\label{HUFF_8c_a21}


Sizes the given frequency array using the specified code list. the code list is a sparse list of the valid members. The valid members are specified either by the non-zero elements in the frequency array or the {\em valid\/} array. 

\begin{Desc}
\item[Returns:]The size, in bits, of the encoded distribution\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em codes}]The code table to use\item[{\em freq}]The frequency table.\end{description}
\end{Desc}
If {\em valid\/} array is non-zero, then this array is indexed by the validity array

If {\em valid\/} array is specified as NULL, then only the non-zero elements of {\em freq\/} are considered valid.

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em valid}]An array of {\em nvalid\/} elements, giving the indices of the valid elements in the frequency array. This may be specified as NULL, in which case, only the non-zero elements of {\em freq\/} are considered valid and {\em nvalid\/} gives the length, not of the validity array, but of the frequency distribution.\item[{\em nvalid}]If {\em valid\/} is\begin{itemize}
\item Non-NULL, then this is the number of entries in the {\em valid\/} array.\item NULL, then this is the number of elements in the frequency array.\end{itemize}
\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a31}{
\index{HUFF.c@{HUFF.c}!is_valid@{is\_\-valid}}
\index{is_valid@{is\_\-valid}!HUFF.c@{HUFF.c}}
\subsubsection[is\_\-valid]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline int is\_\-valid (int {\em idx}, const unsigned int $\ast$ {\em valid}, int {\em nvalid})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a31}


Determines whether the index {\em idx\/} is a member of the valid set of indices. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em ==}]0, No, not a member \item[{\em !=}]0, Yes, is a member\end{description}
\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em idx}]The index being checked \item[{\em valid}]The array of valid indices \item[{\em nvalid}]The number of valid indices\end{description}
\end{Desc}
\hypertarget{HUFF_8c_a35}{
\index{HUFF.c@{HUFF.c}!ndigits_compute@{ndigits\_\-compute}}
\index{ndigits_compute@{ndigits\_\-compute}!HUFF.c@{HUFF.c}}
\subsubsection[ndigits\_\-compute]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline int ndigits\_\-compute (unsigned int {\em value})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HUFF_8c_a35}


Calculate the number of decimal digits in {\em value\/}. 

\begin{Desc}
\item[Returns:]The number of decimal digits in {\em value\/} \end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em value}]The target value\end{description}
\end{Desc}
