/*
 * pqueue.h
 *
 * Definition and declarations of timer priority queue
 * 
 */

#ifndef _PQUEUE_H_
#define _PQUEUE_H_

#include <timer.h>


/* pqueue_element_t */
typedef struct pqueue_element {
	timer_t *timer;
	int prio;
} pqueue_element_t;

/* pqueue_t */
typedef struct {
	pqueue_element_t **array;
	int size;
	int avail;
} pqueue_t;


/* pqueue_create - allocates memory for pqueue_t and initiates the structure */
pqueue_t* pqueue_create(int init_size);


/* pqueue_destroy - frees all memory used by queue if it is empty */
int pqueue_destroy(pqueue_t *queue);


/* pqueue_is_empty - returns 1 if queue empty, else returns 0 */
int pqueue_is_empty(pqueue_t *queue);


/* pqueue_minimum - returns the minimum priority of the queue */
int pqueue_minimum(pqueue_t *queue);


/* pqueue_enqueue - inserts a new element on the end of the queue */
void pqueue_enqueue(pqueue_t *queue, timer_t *timer, int prio);


/* pqueue_dequeue - removes the first element of the queue */
timer_t* pqueue_dequeue(pqueue_t *queue);

/* pqueue_decrease_key - decrease value of a timer */
int pqueue_decrease_prio(pqueue_t *queue, int id, int prio);


#endif
