\doxysection{include/sphinxbase/huff\+\_\+code.h File Reference}
\label{huff__code_8h}\index{include/sphinxbase/huff\_code.h@{include/sphinxbase/huff\_code.h}}


Huffman code and bitstream implementation.  


{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/prim\+\_\+type.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/cmd\+\_\+ln.\+h$>$}\newline
\doxysubsubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef struct \textbf{ huff\+\_\+code\+\_\+s} \textbf{ huff\+\_\+code\+\_\+t}
\end{DoxyCompactItemize}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ \textbf{ huff\+\_\+code\+\_\+build\+\_\+int} (int32 const $\ast$values, int32 const $\ast$frequencies, int nvals)
\begin{DoxyCompactList}\small\item\em Create a codebook from 32-\/bit integer data. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ \textbf{ huff\+\_\+code\+\_\+build\+\_\+str} (char $\ast$const $\ast$values, int32 const $\ast$frequencies, int nvals)
\begin{DoxyCompactList}\small\item\em Create a codebook from string data. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ \textbf{ huff\+\_\+code\+\_\+read} (FILE $\ast$infh)
\begin{DoxyCompactList}\small\item\em Read a codebook from a file. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ huff\+\_\+code\+\_\+write} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc, FILE $\ast$outfh)
\begin{DoxyCompactList}\small\item\em Write a codebook to a file. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ huff\+\_\+code\+\_\+dump} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc, FILE $\ast$dumpfh)
\begin{DoxyCompactList}\small\item\em Print a codebook to a file as text (for debugging) \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ \textbf{ huff\+\_\+code\+\_\+retain} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc)
\begin{DoxyCompactList}\small\item\em Retain a pointer to a Huffman codec object. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ huff\+\_\+code\+\_\+free} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc)
\begin{DoxyCompactList}\small\item\em Release a pointer to a Huffman codec object. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT FILE $\ast$ \textbf{ huff\+\_\+code\+\_\+attach} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc, FILE $\ast$fh, char const $\ast$mode)
\begin{DoxyCompactList}\small\item\em Attach a Huffman codec to a file handle for input/output. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT FILE $\ast$ \textbf{ huff\+\_\+code\+\_\+detach} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc)
\begin{DoxyCompactList}\small\item\em Detach a Huffman codec from its file handle. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ huff\+\_\+code\+\_\+encode\+\_\+int} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc, int32 sym, uint32 $\ast$outcw)
\begin{DoxyCompactList}\small\item\em Encode an integer, writing it to the file handle, if any. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ huff\+\_\+code\+\_\+encode\+\_\+str} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc, char const $\ast$sym, uint32 $\ast$outcw)
\begin{DoxyCompactList}\small\item\em Encode a string, writing it to the file handle, if any. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ huff\+\_\+code\+\_\+decode\+\_\+int} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc, int $\ast$outval, char const $\ast$$\ast$inout\+\_\+data, size\+\_\+t $\ast$inout\+\_\+data\+\_\+len, int $\ast$inout\+\_\+offset)
\begin{DoxyCompactList}\small\item\em Decode an integer, reading it from the file if no data given. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT char const $\ast$ \textbf{ huff\+\_\+code\+\_\+decode\+\_\+str} (\textbf{ huff\+\_\+code\+\_\+t} $\ast$hc, char const $\ast$$\ast$inout\+\_\+data, size\+\_\+t $\ast$inout\+\_\+data\+\_\+len, int $\ast$inout\+\_\+offset)
\begin{DoxyCompactList}\small\item\em Decode a string, reading it from the file if no data given. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Huffman code and bitstream implementation. 

This interface supports building canonical Huffman codes from string and integer values. It also provides support for encoding and decoding from strings and files, and for reading and writing codebooks from files. 

Definition in file \textbf{ huff\+\_\+code.\+h}.



\doxysubsection{Typedef Documentation}
\label{huff__code_8h_a99a5188e6a18682c96100cd5232af0f4} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_t@{huff\_code\_t}}
\index{huff\_code\_t@{huff\_code\_t}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_t}
{\footnotesize\ttfamily typedef struct \textbf{ huff\+\_\+code\+\_\+s} \textbf{ huff\+\_\+code\+\_\+t}}



Definition at line \textbf{ 57} of file \textbf{ huff\+\_\+code.\+h}.



\doxysubsection{Function Documentation}
\label{huff__code_8h_abab6f593fd6ab6d88a2be2d6e785408e} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_attach@{huff\_code\_attach}}
\index{huff\_code\_attach@{huff\_code\_attach}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_attach()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT FILE $\ast$ huff\+\_\+code\+\_\+attach (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc,  }\item[{FILE $\ast$}]{fh,  }\item[{char const $\ast$}]{mode }\end{DoxyParamCaption})}



Attach a Huffman codec to a file handle for input/output. 



Definition at line \textbf{ 475} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ bit\+\_\+encode\+\_\+attach()}, \textbf{ huff\+\_\+code\+\_\+attach()}, and \textbf{ huff\+\_\+code\+\_\+detach()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+attach()}.

\label{huff__code_8h_a60f8f0259db728c8714074842380d15d} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_build\_int@{huff\_code\_build\_int}}
\index{huff\_code\_build\_int@{huff\_code\_build\_int}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_build\_int()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ huff\+\_\+code\+\_\+build\+\_\+int (\begin{DoxyParamCaption}\item[{int32 const $\ast$}]{values,  }\item[{int32 const $\ast$}]{frequencies,  }\item[{int}]{nvals }\end{DoxyParamCaption})}



Create a codebook from 32-\/bit integer data. 



Definition at line \textbf{ 229} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ ckd\+\_\+calloc}, \textbf{ E\+\_\+\+ERROR}, \textbf{ heap\+\_\+destroy()}, \textbf{ heap\+\_\+insert()}, \textbf{ heap\+\_\+new()}, \textbf{ huff\+\_\+code\+\_\+build\+\_\+int()}, and \textbf{ huff\+\_\+code\+\_\+free()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+build\+\_\+int()}.

\label{huff__code_8h_a64dd448d1345e910ae255ee71e668063} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_build\_str@{huff\_code\_build\_str}}
\index{huff\_code\_build\_str@{huff\_code\_build\_str}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_build\_str()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ huff\+\_\+code\+\_\+build\+\_\+str (\begin{DoxyParamCaption}\item[{char $\ast$const $\ast$}]{values,  }\item[{int32 const $\ast$}]{frequencies,  }\item[{int}]{nvals }\end{DoxyParamCaption})}



Create a codebook from string data. 



Definition at line \textbf{ 269} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ ckd\+\_\+calloc}, \textbf{ E\+\_\+\+ERROR}, \textbf{ heap\+\_\+destroy()}, \textbf{ heap\+\_\+insert()}, \textbf{ heap\+\_\+new()}, \textbf{ huff\+\_\+code\+\_\+build\+\_\+str()}, and \textbf{ huff\+\_\+code\+\_\+free()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+build\+\_\+str()}.

\label{huff__code_8h_a9155dd07a0a24393ef0e4e66cb314140} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_decode\_int@{huff\_code\_decode\_int}}
\index{huff\_code\_decode\_int@{huff\_code\_decode\_int}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_decode\_int()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int huff\+\_\+code\+\_\+decode\+\_\+int (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc,  }\item[{int $\ast$}]{outval,  }\item[{char const $\ast$$\ast$}]{inout\+\_\+data,  }\item[{size\+\_\+t $\ast$}]{inout\+\_\+data\+\_\+len,  }\item[{int $\ast$}]{inout\+\_\+offset }\end{DoxyParamCaption})}



Decode an integer, reading it from the file if no data given. 



Definition at line \textbf{ 612} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ huff\+\_\+code\+\_\+decode\+\_\+int()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+decode\+\_\+int()}.

\label{huff__code_8h_ad43a402d653013868245e233e5215c41} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_decode\_str@{huff\_code\_decode\_str}}
\index{huff\_code\_decode\_str@{huff\_code\_decode\_str}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_decode\_str()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT char const  $\ast$ huff\+\_\+code\+\_\+decode\+\_\+str (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc,  }\item[{char const $\ast$$\ast$}]{inout\+\_\+data,  }\item[{size\+\_\+t $\ast$}]{inout\+\_\+data\+\_\+len,  }\item[{int $\ast$}]{inout\+\_\+offset }\end{DoxyParamCaption})}



Decode a string, reading it from the file if no data given. 



Definition at line \textbf{ 634} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ huff\+\_\+code\+\_\+decode\+\_\+str()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+decode\+\_\+str()}.

\label{huff__code_8h_a6b7d4a0d6b196c94d5847ff947a7e86e} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_detach@{huff\_code\_detach}}
\index{huff\_code\_detach@{huff\_code\_detach}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_detach()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT FILE $\ast$ huff\+\_\+code\+\_\+detach (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc }\end{DoxyParamCaption})}



Detach a Huffman codec from its file handle. 



Definition at line \textbf{ 486} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ bit\+\_\+encode\+\_\+flush()}, \textbf{ bit\+\_\+encode\+\_\+free()}, and \textbf{ huff\+\_\+code\+\_\+detach()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+attach()}, and \textbf{ huff\+\_\+code\+\_\+detach()}.

\label{huff__code_8h_a821658831cbe9b1199c756435d0ad4aa} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_dump@{huff\_code\_dump}}
\index{huff\_code\_dump@{huff\_code\_dump}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_dump()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int huff\+\_\+code\+\_\+dump (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc,  }\item[{FILE $\ast$}]{dumpfh }\end{DoxyParamCaption})}



Print a codebook to a file as text (for debugging) 



Definition at line \textbf{ 420} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ huff\+\_\+code\+\_\+dump()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+dump()}.

\label{huff__code_8h_acf369555b8784eee944f7ebc97b6b825} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_encode\_int@{huff\_code\_encode\_int}}
\index{huff\_code\_encode\_int@{huff\_code\_encode\_int}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_encode\_int()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int huff\+\_\+code\+\_\+encode\+\_\+int (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc,  }\item[{int32}]{sym,  }\item[{uint32 $\ast$}]{outcw }\end{DoxyParamCaption})}



Encode an integer, writing it to the file handle, if any. 



Definition at line \textbf{ 500} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ bit\+\_\+encode\+\_\+write\+\_\+cw()}, \textbf{ hash\+\_\+table\+\_\+lookup\+\_\+bkey()}, and \textbf{ huff\+\_\+code\+\_\+encode\+\_\+int()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+encode\+\_\+int()}.

\label{huff__code_8h_a24fe76f501a7a0485f3e9485c60fae32} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_encode\_str@{huff\_code\_encode\_str}}
\index{huff\_code\_encode\_str@{huff\_code\_encode\_str}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_encode\_str()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int huff\+\_\+code\+\_\+encode\+\_\+str (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc,  }\item[{char const $\ast$}]{sym,  }\item[{uint32 $\ast$}]{outcw }\end{DoxyParamCaption})}



Encode a string, writing it to the file handle, if any. 



Definition at line \textbf{ 516} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ bit\+\_\+encode\+\_\+write\+\_\+cw()}, \textbf{ hash\+\_\+table\+\_\+lookup()}, and \textbf{ huff\+\_\+code\+\_\+encode\+\_\+str()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+encode\+\_\+str()}.

\label{huff__code_8h_ac8678d07a65af1963cc0b3bd8b10d646} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_free@{huff\_code\_free}}
\index{huff\_code\_free@{huff\_code\_free}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_free()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int huff\+\_\+code\+\_\+free (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc }\end{DoxyParamCaption})}



Release a pointer to a Huffman codec object. 



Definition at line \textbf{ 450} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ ckd\+\_\+free()}, \textbf{ hash\+\_\+table\+\_\+free()}, and \textbf{ huff\+\_\+code\+\_\+free()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+build\+\_\+int()}, \textbf{ huff\+\_\+code\+\_\+build\+\_\+str()}, \textbf{ huff\+\_\+code\+\_\+free()}, and \textbf{ huff\+\_\+code\+\_\+read()}.

\label{huff__code_8h_ab56d56ccf6f48d4bdd8d5ceb4d9e260c} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_read@{huff\_code\_read}}
\index{huff\_code\_read@{huff\_code\_read}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_read()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ huff\+\_\+code\+\_\+read (\begin{DoxyParamCaption}\item[{FILE $\ast$}]{infh }\end{DoxyParamCaption})}



Read a codebook from a file. 



Definition at line \textbf{ 309} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ ckd\+\_\+calloc}, \textbf{ fread\+\_\+line()}, \textbf{ hash\+\_\+table\+\_\+enter()}, \textbf{ hash\+\_\+table\+\_\+enter\+\_\+bkey()}, \textbf{ hash\+\_\+table\+\_\+new()}, \textbf{ huff\+\_\+code\+\_\+free()}, and \textbf{ huff\+\_\+code\+\_\+read()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+read()}.

\label{huff__code_8h_aa0f019f5fdff8f709a54824b5a2d7c83} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_retain@{huff\_code\_retain}}
\index{huff\_code\_retain@{huff\_code\_retain}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_retain()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT \textbf{ huff\+\_\+code\+\_\+t} $\ast$ huff\+\_\+code\+\_\+retain (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc }\end{DoxyParamCaption})}



Retain a pointer to a Huffman codec object. 



Definition at line \textbf{ 443} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ huff\+\_\+code\+\_\+retain()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+retain()}.

\label{huff__code_8h_a6b91641e852a8eb4c4d32f40ff6dd055} 
\index{huff\_code.h@{huff\_code.h}!huff\_code\_write@{huff\_code\_write}}
\index{huff\_code\_write@{huff\_code\_write}!huff\_code.h@{huff\_code.h}}
\doxysubsubsection{huff\_code\_write()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int huff\+\_\+code\+\_\+write (\begin{DoxyParamCaption}\item[{\textbf{ huff\+\_\+code\+\_\+t} $\ast$}]{hc,  }\item[{FILE $\ast$}]{outfh }\end{DoxyParamCaption})}



Write a codebook to a file. 



Definition at line \textbf{ 368} of file \textbf{ huff\+\_\+code.\+c}.



References \textbf{ huff\+\_\+code\+\_\+write()}.



Referenced by \textbf{ huff\+\_\+code\+\_\+write()}.

