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
Returns the element at the specified position in this list, or NULL if the queue does not contain an index'th element.
- Parameters:
-
q | a pointer to an instance of the priqueue_t data structure |
index | position of retrieved element |
- Returns:
- the index'th element in the queue
-
NULL if the queue does not contain the index'th element
Destroys and frees all the memory associated with q.
- Parameters:
-
q | a 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:
-
q | a pointer to an instance of the priqueue_t data structure |
comparer | a function pointer that compares two elements. See also Compare Function |
Inserts the specified element into this priority queue.
- Parameters:
-
q | a pointer to an instance of the priqueue_t data structure |
ptr | a 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.
Retrieves, but does not remove, the head of this queue, returning NULL if this queue is empty.
- Parameters:
-
q | a 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
Retrieves and removes the head of this queue, or NULL if this queue is empty.
- Parameters:
-
q | a 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:
-
q | a pointer to an instance of the priqueue_t data structure |
ptr | address 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:
-
q | a pointer to an instance of the priqueue_t data structure |
index | position of element to be removed |
- Returns:
- the element removed from the queue
-
NULL if the specified index does not exist
Returns the number of elements in the queue.
- Parameters:
-
q | a pointer to an instance of the priqueue_t data structure |
- Returns:
- the number of elements in the queue