/**
 * @file heap.h
 * @author Joe Wingbermuehle
 * @date 2007-07-05
 *
 * @brief Binary Heap
 *
 */

#ifndef HEAP_H
#define HEAP_H

/** Heap object. */
typedef void *Heap;

/** Comparator for items in a heap.
 * @param a The first item.
 * @param b The second item.
 * @return The ordering of a and b.
 *           0 if a and b are equivalent.
 *         < 0 if a comes before b.
 *         > 0 if b comes before a.
 */
typedef int (*HeapComparator)(const void *a, const void *b);

/** Create an empty heap.
 * @param comparator The comparator to use.
 * @return An empty heap.
 */
Heap *CreateHeap(HeapComparator comparator);

/** Destroy a heap.
 * @param heap the heap to destroy.
 */
void DestroyHeap(Heap *heap);

/** Insert an item to the heap.
 * @param heap The heap.
 * @param value The value to insert.
 */
void InsertHeap(Heap *heap, void *value);

/** Remove the least item from a heap.
 * @param heap The heap.
 * @return The least item.
 */
void *RemoveHeap(Heap *heap);

/** Get the least item from a heap.
 * @param heap The heap.
 * @return The least item.
 */
void *GetHeap(Heap *heap);

/** Get the size of a heap.
 * @param heap The heap.
 * @return The number of items in the heap.
 */
int GetHeapSize(Heap *heap);

#endif /* HEAP_H */

