/* Priority queue */

#ifndef _CPQUEUE_H
#define _CPQUEUE_H 1

#include "cvector.h"

typedef struct PQueue {
  /* You fill this in */
  Vector *v;
  int    (*cmp)(void *, void *);
} PQueue;

/* new_PQueue()
  
   Creates a new priority queue object. Size specifies the number
   elements and has the same meaning as that used with new_Vector().
   That is, if size > 0, it specifies the maximum size of the queue.
   If size < 0, the queue can grow to arbitrary size.  

   The second argument cmp, specifies a comparison function
   that is used to compare items placed into the queue.  This
   is used to rank the items from highest to lowest priority.

   The compare function returns the same value as functions
   like strcmp() or the compare function to qsort.  That is,
   a 0 indicates equals, negative indicates less than, and
   positive indicates greater than. */

extern PQueue *new_PQueue(int size, int (*cmp)(void *,void *));

/* delete_PQueue()

   Deletes a priority queue. */
extern void delete_PQueue(PQueue *p);

/* PQueue_enqueue()

   Places a new item on the priority queue.  

   The function returns the number of items on the queue
   on success, -1 if the queue is full and the item couldn't
   be placed. */

extern int PQueue_enqueue(PQueue *p, void *item);

/* PQueue_dequeue()

   Returns the item with the highest priority from the queue
   and removes it from the queue. To determine which item has
   the highest priority, the cmp function given to new_PQueue
   should be used. */

extern void *PQueue_dequeue(PQueue *p);

/* PQueue_head()

   Returns the item with the highest priority on the queue,
   but doesn't remove it from the queue.  You would use this
   to examine the first item without taking it off the queue */

extern void *PQueue_head(const PQueue *p);

/* PQueue_len()

   Return the total number of items in the queue */

extern int PQueue_len(const PQueue *p);

#endif


