\doxysection{include/sphinxbase/heap.h File Reference}
\label{heap_8h}\index{include/sphinxbase/heap.h@{include/sphinxbase/heap.h}}


Heap Implementation.  


{\ttfamily \#include $<$stdlib.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/sphinxbase\+\_\+export.\+h$>$}\newline
{\ttfamily \#include $<$sphinxbase/prim\+\_\+type.\+h$>$}\newline
\doxysubsubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef struct \textbf{ heap\+\_\+s} \textbf{ heap\+\_\+t}
\end{DoxyCompactItemize}
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
SPHINXBASE\+\_\+\+EXPORT \textbf{ heap\+\_\+t} $\ast$ \textbf{ heap\+\_\+new} (void)
\begin{DoxyCompactList}\small\item\em Allocate a new heap and return handle to it. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ heap\+\_\+insert} (\textbf{ heap\+\_\+t} $\ast$heap, void $\ast$data, int32 val)
\begin{DoxyCompactList}\small\item\em Insert a new item into the given heap. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ heap\+\_\+top} (\textbf{ heap\+\_\+t} $\ast$heap, void $\ast$$\ast$data, int32 $\ast$val)
\begin{DoxyCompactList}\small\item\em Return the topmost item in the heap. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ heap\+\_\+pop} (\textbf{ heap\+\_\+t} $\ast$heap, void $\ast$$\ast$data, int32 $\ast$val)
\begin{DoxyCompactList}\small\item\em Like heap\+\_\+top but also pop the top item off the heap. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ heap\+\_\+remove} (\textbf{ heap\+\_\+t} $\ast$heap, void $\ast$data)
\begin{DoxyCompactList}\small\item\em Remove an item from the heap. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT size\+\_\+t \textbf{ heap\+\_\+size} (\textbf{ heap\+\_\+t} $\ast$heap)
\begin{DoxyCompactList}\small\item\em Return the number of items in the heap. \end{DoxyCompactList}\item 
SPHINXBASE\+\_\+\+EXPORT int \textbf{ heap\+\_\+destroy} (\textbf{ heap\+\_\+t} $\ast$heap)
\begin{DoxyCompactList}\small\item\em Destroy the given heap; free the heap nodes. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Heap Implementation. 

General Comment\+: Sorted heap structure with three main operations\+:


\begin{DoxyEnumerate}
\item Insert a data item (with two attributes\+: an application supplied pointer and an integer value; the heap is maintained in ascending order of the integer value).
\item Return the currently topmost item (i.\+e., item with smallest associated value).
\item Return the currently topmost item and pop it off the heap. 
\end{DoxyEnumerate}

Definition in file \textbf{ heap.\+h}.



\doxysubsection{Typedef Documentation}
\label{heap_8h_a0ffa4ec8648c254bf19eee352b69dc7a} 
\index{heap.h@{heap.h}!heap\_t@{heap\_t}}
\index{heap\_t@{heap\_t}!heap.h@{heap.h}}
\doxysubsubsection{heap\_t}
{\footnotesize\ttfamily typedef struct \textbf{ heap\+\_\+s} \textbf{ heap\+\_\+t}}



Definition at line \textbf{ 94} of file \textbf{ heap.\+h}.



\doxysubsection{Function Documentation}
\label{heap_8h_ab12b1efd6392eb574d2da9c981e7320c} 
\index{heap.h@{heap.h}!heap\_destroy@{heap\_destroy}}
\index{heap\_destroy@{heap\_destroy}!heap.h@{heap.h}}
\doxysubsubsection{heap\_destroy()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int heap\+\_\+destroy (\begin{DoxyParamCaption}\item[{\textbf{ heap\+\_\+t} $\ast$}]{heap }\end{DoxyParamCaption})}



Destroy the given heap; free the heap nodes. 

NOTE\+: Data pointers in the nodes are NOT freed. Return value\+: 0 if successful, -\/1 otherwise. 

Definition at line \textbf{ 281} of file \textbf{ heap.\+c}.



References \textbf{ ckd\+\_\+free()}, \textbf{ heap\+\_\+destroy()}, and \textbf{ heap\+\_\+pop()}.



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

\label{heap_8h_a64bcded2de5086c5d246ff760caa74a3} 
\index{heap.h@{heap.h}!heap\_insert@{heap\_insert}}
\index{heap\_insert@{heap\_insert}!heap.h@{heap.h}}
\doxysubsubsection{heap\_insert()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int heap\+\_\+insert (\begin{DoxyParamCaption}\item[{\textbf{ heap\+\_\+t} $\ast$}]{heap,  }\item[{void $\ast$}]{data,  }\item[{int32}]{val }\end{DoxyParamCaption})}



Insert a new item into the given heap. 

Return value\+: 0 if successful, -\/1 otherwise. 
\begin{DoxyParams}{Parameters}
{\em heap} & In\+: Heap into which item is to be inserted  \\
\hline
{\em data} & In\+: Application-\/determined data pointer  \\
\hline
{\em val} & In\+: According to item entered in sorted heap \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 161} of file \textbf{ heap.\+c}.



References \textbf{ heap\+\_\+insert()}.



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

\label{heap_8h_a5fadba3799cf24ebc6640d09d735342d} 
\index{heap.h@{heap.h}!heap\_new@{heap\_new}}
\index{heap\_new@{heap\_new}!heap.h@{heap.h}}
\doxysubsubsection{heap\_new()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT \textbf{ heap\+\_\+t} $\ast$ heap\+\_\+new (\begin{DoxyParamCaption}\item[{void}]{ }\end{DoxyParamCaption})}



Allocate a new heap and return handle to it. 



Definition at line \textbf{ 113} of file \textbf{ heap.\+c}.



References \textbf{ ckd\+\_\+calloc}, and \textbf{ heap\+\_\+new()}.



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

\label{heap_8h_a387c8913b4c62ad1a5c4702a4e6dbdbf} 
\index{heap.h@{heap.h}!heap\_pop@{heap\_pop}}
\index{heap\_pop@{heap\_pop}!heap.h@{heap.h}}
\doxysubsubsection{heap\_pop()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int heap\+\_\+pop (\begin{DoxyParamCaption}\item[{\textbf{ heap\+\_\+t} $\ast$}]{heap,  }\item[{void $\ast$$\ast$}]{data,  }\item[{int32 $\ast$}]{val }\end{DoxyParamCaption})}



Like heap\+\_\+top but also pop the top item off the heap. 



Definition at line \textbf{ 209} of file \textbf{ heap.\+c}.



References \textbf{ heapnode\+\_\+s\+::data}, \textbf{ heap\+\_\+pop()}, and \textbf{ heapnode\+\_\+s\+::val}.



Referenced by \textbf{ heap\+\_\+destroy()}, and \textbf{ heap\+\_\+pop()}.

\label{heap_8h_aa2dbc059f9707e434098694e8c69157e} 
\index{heap.h@{heap.h}!heap\_remove@{heap\_remove}}
\index{heap\_remove@{heap\_remove}!heap.h@{heap.h}}
\doxysubsubsection{heap\_remove()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int heap\+\_\+remove (\begin{DoxyParamCaption}\item[{\textbf{ heap\+\_\+t} $\ast$}]{heap,  }\item[{void $\ast$}]{data }\end{DoxyParamCaption})}



Remove an item from the heap. 



Definition at line \textbf{ 266} of file \textbf{ heap.\+c}.



References \textbf{ heap\+\_\+remove()}.



Referenced by \textbf{ heap\+\_\+remove()}.

\label{heap_8h_a1c713d67123e96974505edfa4346cb0f} 
\index{heap.h@{heap.h}!heap\_size@{heap\_size}}
\index{heap\_size@{heap\_size}!heap.h@{heap.h}}
\doxysubsubsection{heap\_size()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT size\+\_\+t heap\+\_\+size (\begin{DoxyParamCaption}\item[{\textbf{ heap\+\_\+t} $\ast$}]{heap }\end{DoxyParamCaption})}



Return the number of items in the heap. 



Definition at line \textbf{ 273} of file \textbf{ heap.\+c}.



References \textbf{ heap\+\_\+size()}, and \textbf{ heapnode\+\_\+s\+::nr}.



Referenced by \textbf{ heap\+\_\+size()}.

\label{heap_8h_ae70da6b59215654c2cd5ec177eaf2aec} 
\index{heap.h@{heap.h}!heap\_top@{heap\_top}}
\index{heap\_top@{heap\_top}!heap.h@{heap.h}}
\doxysubsubsection{heap\_top()}
{\footnotesize\ttfamily SPHINXBASE\+\_\+\+EXPORT int heap\+\_\+top (\begin{DoxyParamCaption}\item[{\textbf{ heap\+\_\+t} $\ast$}]{heap,  }\item[{void $\ast$$\ast$}]{data,  }\item[{int32 $\ast$}]{val }\end{DoxyParamCaption})}



Return the topmost item in the heap. 

Return value\+: 1 if heap is not empty and the topmost value is returned; 0 if heap is empty; -\/1 if some error occurred. 
\begin{DoxyParams}{Parameters}
{\em heap} & In\+: Heap whose topmost item is to be returned  \\
\hline
{\em data} & Out\+: Data pointer associated with the topmost item  \\
\hline
{\em val} & Out\+: Value associated with the topmost item \\
\hline
\end{DoxyParams}


Definition at line \textbf{ 221} of file \textbf{ heap.\+c}.



References \textbf{ heapnode\+\_\+s\+::data}, \textbf{ heap\+\_\+top()}, and \textbf{ heapnode\+\_\+s\+::val}.



Referenced by \textbf{ heap\+\_\+top()}.

