include/heap.h File Reference

Heap Implementation. More...

#include <sphinxbase_export.h>
#include <prim_type.h>

Go to the source code of this file.

Typedefs

typedef void * heap_t

Functions

SPHINXBASE_EXPORT heap_t heap_new (void)
 Allocate a new heap and return handle to it.
SPHINXBASE_EXPORT int32 heap_insert (heap_t heap, void *data, int32 val)
 Insert a new item into the given heap.
SPHINXBASE_EXPORT int32 heap_top (heap_t heap, void **data, int32 *val)
 Return the topmost item in the heap.
SPHINXBASE_EXPORT int32 heap_pop (heap_t heap, void **data, int32 *val)
 Like heap_top but also pop the top item off the heap.
SPHINXBASE_EXPORT int32 heap_destroy (heap_t heap)
 Destroy the given heap; free the heap nodes.


Detailed Description

Heap Implementation.

General Comment: Sorted heap structure with three main operations:

1. 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). 2. Return the currently topmost item (i.e., item with smallest associated value). 3. Return the currently topmost item and pop it off the heap.

Definition in file heap.h.


Function Documentation

SPHINXBASE_EXPORT int32 heap_destroy ( heap_t  heap  ) 

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 246 of file heap.c.

References ckd_free(), heap_destroy(), and heap_pop().

Referenced by heap_destroy().

SPHINXBASE_EXPORT int32 heap_insert ( heap_t  heap,
void *  data,
int32  val 
)

Insert a new item into the given heap.

Return value: 0 if successful, -1 otherwise.

Parameters:
heap  In: Heap into which item is to be inserted
data  In: Application-determined data pointer
val  In: According to item entered in sorted heap

Definition at line 155 of file heap.c.

References heap_insert().

Referenced by heap_insert().

SPHINXBASE_EXPORT int32 heap_top ( heap_t  heap,
void **  data,
int32 *  val 
)

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.

Parameters:
heap  In: Heap whose topmost item is to be returned
data  Out: Data pointer associated with the topmost item
val  Out: Value associated with the topmost item

Definition at line 228 of file heap.c.

References heap_top().

Referenced by heap_top().


Generated on Mon Jul 7 22:32:38 2008 for SphinxBase by  doxygen 1.5.5