MP5 Schedule Me!
libpriqueue/libpriqueue.h File Reference

Go to the source code of this file.

Data Structures

struct  priqueue_t
 Priqueue Data Structure. More...

Functions

void priqueue_init (priqueue_t *q, int(*comparer)(const void *, const void *))
 Initializes the priqueue_t data structure.
int priqueue_offer (priqueue_t *q, void *ptr)
 Inserts the specified element into this priority queue.
void * priqueue_peek (priqueue_t *q)
 Retrieves, but does not remove, the head of this queue, returning NULL if this queue is empty.
void * priqueue_poll (priqueue_t *q)
 Retrieves and removes the head of this queue, or NULL if this queue is empty.
void * priqueue_at (priqueue_t *q, int index)
 Returns the element at the specified position in this list, or NULL if the queue does not contain an index'th element.
int priqueue_remove (priqueue_t *q, void *ptr)
 Removes all instances of ptr from the queue.
void * priqueue_remove_at (priqueue_t *q, int index)
 Removes the specified index from the queue, moving later elements up a spot in the queue to fill the gap.
int priqueue_size (priqueue_t *q)
 Returns the number of elements in the queue.
void priqueue_destroy (priqueue_t *q)
 Destroys and frees all the memory associated with q.

Detailed Description


Function Documentation

void* priqueue_at ( priqueue_t q,
int  index 
)

Returns the element at the specified position in this list, or NULL if the queue does not contain an index'th element.

Parameters:
qa pointer to an instance of the priqueue_t data structure
indexposition of retrieved element
Returns:
the index'th element in the queue
NULL if the queue does not contain the index'th element
void priqueue_destroy ( priqueue_t q)

Destroys and frees all the memory associated with q.

Parameters:
qa pointer to an instance of the priqueue_t data structure
void priqueue_init ( priqueue_t q,
int(*)(const void *, const void *)  comparer 
)

Initializes the priqueue_t data structure.

Assumtions

  • You may assume this function will only be called once per instance of priqueue_t
  • You may assume this function will be the first function called using an instance of priqueue_t.
    Parameters:
    qa pointer to an instance of the priqueue_t data structure
    comparera function pointer that compares two elements. See also Compare Function
int priqueue_offer ( priqueue_t q,
void *  ptr 
)

Inserts the specified element into this priority queue.

Parameters:
qa pointer to an instance of the priqueue_t data structure
ptra pointer to the data to be inserted into the priority queue
Returns:
The zero-based index where ptr is stored in the priority queue, where 0 indicates that ptr was stored at the front of the priority queue.
void* priqueue_peek ( priqueue_t q)

Retrieves, but does not remove, the head of this queue, returning NULL if this queue is empty.

Parameters:
qa pointer to an instance of the priqueue_t data structure
Returns:
pointer to element at the head of the queue
NULL if the queue is empty
void* priqueue_poll ( priqueue_t q)

Retrieves and removes the head of this queue, or NULL if this queue is empty.

Parameters:
qa pointer to an instance of the priqueue_t data structure
Returns:
the head of this queue
NULL if this queue is empty
int priqueue_remove ( priqueue_t q,
void *  ptr 
)

Removes all instances of ptr from the queue.

This function should not use the comparer function, but check if the data contained in each element of the queue is equal (==) to ptr.

Parameters:
qa pointer to an instance of the priqueue_t data structure
ptraddress of element to be removed
Returns:
the number of entries removed
void* priqueue_remove_at ( priqueue_t q,
int  index 
)

Removes the specified index from the queue, moving later elements up a spot in the queue to fill the gap.

Parameters:
qa pointer to an instance of the priqueue_t data structure
indexposition of element to be removed
Returns:
the element removed from the queue
NULL if the specified index does not exist
int priqueue_size ( priqueue_t q)

Returns the number of elements in the queue.

Parameters:
qa pointer to an instance of the priqueue_t data structure
Returns:
the number of elements in the queue
 All Data Structures Files Functions Enumerations