//Deian Stefan
//heap.h and heap.c were part of Data Structures and Algorithms 2
//heap.h was originally written by Prof. Sable, but modified later
#ifndef __HEAP_H__
#define __HEAP_H__
struct heap;
typedef struct heap heap_t;
typedef heap_t *pheap_t;

// 
// create_heap - Creates a binary heap with the specified capacity
//
// Returns a pointer to the heap if successful, NULL otherwise.
//
pheap_t create_heap(int capacity);

//
// insert - Inserts a new node into the binary heap
//
// Inserts a node with the specified data pointer, key,
// and id number into the heap.  They key is used to
// determine the final position of the new node.
//
// Returns:
//   0 on success
//   1 if the id is not in the appropriate range (1 to capacity)
//   2 if a node with the given id already exists
//   3 if the heap is already filled to capacity
//
int insert(pheap_t, void *pData, int key, int id);

//
// set_key - set the key of the specified node to the specified value
//
// Returns:
//   0 on success
//   1 if the id is not in the appropriate range (1 to capacity)
//   2 if a node with the given id does not exist
//
int set_key(pheap_t, int id, int key);

//
// delete_min - return the data associated with the smallest key
//             and delete that node from the binary heap
//
// If pKey is supplied (i.e., it is not NULL), write to that address
// the key of the node being deleted.  If pId is supplied, write to
// that address the id of the node being deleted.
//
// Returns a pointer to void that points to the data deleted.
// If the heap is empty, returns NULL.
//
void *delete_min(pheap_t, int *pKey, int *pId);

//
// delete - delete the node with the specified id from the binary heap
//
// If ppData is supplied (i.e., it is not NULL), it is filled in with
// the address of the data associated with the deleted node.
//
// Returns:
//   0 on success
//   1 if the id is not in the appropriate range (1 to capacity)
//   2 if a node with the given id does not exist
//
int delete(pheap_t, int id, void *ppData);

//
// get_min - return the data associated with the smallest key
//             from the binary heap
//
// If pKey is supplied (i.e., it is not NULL), write to that address
// the key of the node.  If pId is supplied, write to that address 
// the id of the node.
//
// Returns a pointer to void that points to the data in the node.
// If the heap is empty, returns NULL.
//
void *get_min(pheap_t, int *pKey, int *pId);

//
// get_by_id - get the key and data based on the id
//
// Returns:
//   0 on success
//   1 if the id is not in the appropriate range (1 to capacity)
//   2 if a node with the given id does not exist
//
int get_by_id(pheap_t, int id, int *key,void *pData);
#endif

