Go to the source code of this file.
|
void | priqueue_init (priqueue_t *q, int(*comparer)(const void *, const void *)) |
| Initializes the priqueue_t data structure. More...
|
|
unsigned int | priqueue_offer (priqueue_t *q, void *ptr) |
| Insert the specified element into this priority queue. More...
|
|
void * | priqueue_peek (priqueue_t *q) |
| Retrieves, but does not remove, the head of this queue, returning NULL if this queue is empty. More...
|
|
void * | priqueue_poll (priqueue_t *q) |
| Retrieves and removes the head of this queue, or NULL if this queue is empty. More...
|
|
void * | priqueue_at (priqueue_t *q, unsigned int index) |
| Returns the element at the specified position in this list, or NULL if the queue does not contain an index'th element. More...
|
|
unsigned int | priqueue_remove (priqueue_t *q, void *ptr) |
| Removes all instances of ptr from the queue. More...
|
|
void * | priqueue_remove_at (priqueue_t *q, unsigned int index) |
| Removes the specified index from the queue, moving later elements up a spot in the queue to fill the gap. More...
|
|
unsigned int | priqueue_size (priqueue_t *q) |
| Return the number of elements in the queue. More...
|
|
void | priqueue_destroy (priqueue_t *q) |
| Destroys and frees all the memory associated with q. More...
|
|
void | priqueue_print (priqueue_t *q, char *str) |
|
◆ priqueue_at()
void* priqueue_at |
( |
priqueue_t * |
q, |
|
|
unsigned 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
-
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
◆ priqueue_destroy()
Destroys and frees all the memory associated with q.
- Parameters
-
q | a pointer to an instance of the priqueue_t data structure |
◆ priqueue_init()
void priqueue_init |
( |
priqueue_t * |
q, |
|
|
int(*)(const void *, const void *) |
comparer |
|
) |
| |
Initializes the priqueue_t data structure.
Assumptions
- 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 |
◆ priqueue_offer()
unsigned int priqueue_offer |
( |
priqueue_t * |
q, |
|
|
void * |
ptr |
|
) |
| |
Insert 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.
◆ priqueue_peek()
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
◆ priqueue_poll()
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
◆ priqueue_remove()
unsigned 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
◆ priqueue_remove_at()
void* priqueue_remove_at |
( |
priqueue_t * |
q, |
|
|
unsigned 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
◆ priqueue_size()
Return 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