Site hosted by Angelfire.com: Build your free website today!

(c) 2002 - Pedro Flynn <pflynn@microsoftsucks.org>

PQueue


typedef struct _PQueueElement {
    int priority;   
    void* data;
}PQueueElement;

typedef struct _PQueue {
    int size;
    PQueueElement* elements;
    destroyfunc* destroy;
} PQueue;


    The PQueue data structure represents a priority queue.


Related functions and macros



PQueue* pqueue_create(destroyfunc* destroy)

description: creates a new, empty priority queue. The destroy parameter is a pointer to a user-defined destroyfunc. This function will be used by pqueue_destroy to free dynamically allocated data. If the data to be inserted in the priority queue should not be freed, destroy should be set to NULL.

return value: a pointer to a new PQueue data structure, or NULL if the allocation fails.

since: YACLib 1.0

int pqueue_enqueue(PQueue* pqueue, const void* data, int priority)

description: enqueue an element in the priority queue specified by pqueue, with priority priority. The new element stores a pointer to data.

return value:
0 if the element could be enqueued, -1 otherwise.

since:
YACLib 1.0

int pqueue_dequeue(PQueue* pqueue,void** data)

description: dequeue the highest priority element from the priority queue specified by pqueue. Upon return, data points to the data stored in the element that was dequeued.

return value:
0 if the element could be dequeued, -1 otherwise.

since:
YACLib 1.0
void pqueue_dequeue_all(PQueue* pqueue)

description: dequeue all the elements from the priority queue specified by pqueue.

return value:
none.

since:
YACLib 1.0
void pqueue_destroy(PQueue* pqueue)

description: destroys the priority queue specified by pqueue. It will remove all the elements from the priority queue and call the destroyfunc function passed to pqueue_create for each element as it is removed, provided destroy wasn't set to NULL.

return value:
none.

since: YACLib 1.0
int pqueue_size(PQueue* pqueue)

description: macro that evaluates to the number of elements in the priority queue specified by pqueue.

return value:
the number of elements in the priority queue specified by pqueue.

since: YACLib 1.0