reactor-c
C Runtime for Lingua Franca
|
Priority queue that uses tags for sorting. More...
#include <stdlib.h>
#include <stdint.h>
#include "pqueue_tag.h"
#include "util.h"
#include "low_level_platform.h"
Functions | |
int | pqueue_tag_compare (pqueue_pri_t priority1, pqueue_pri_t priority2) |
Callback comparison function for the tag-based priority queue. Return -1 if the first argument is less than second, 0 if the two arguments are the same, and 1 otherwise. This function is of type pqueue_cmp_pri_f. | |
pqueue_tag_t * | pqueue_tag_init (size_t initial_size) |
Create a priority queue sorted by tags. | |
pqueue_tag_t * | pqueue_tag_init_customize (size_t initial_size, pqueue_cmp_pri_f cmppri, pqueue_eq_elem_f eqelem, pqueue_print_entry_f prt) |
Create a priority queue that stores elements with a particular payload. | |
void | pqueue_tag_free (pqueue_tag_t *q) |
Free all memory used by the queue including elements that are marked dynamic. | |
size_t | pqueue_tag_size (pqueue_tag_t *q) |
Return the size of the queue. | |
int | pqueue_tag_insert (pqueue_tag_t *q, pqueue_tag_element_t *d) |
Insert an element into the queue. | |
int | pqueue_tag_insert_tag (pqueue_tag_t *q, tag_t t) |
Insert a tag into the queue. | |
pqueue_tag_element_t * | pqueue_tag_find_with_tag (pqueue_tag_t *q, tag_t t) |
Return the first item with the specified tag or NULL if there is none. | |
pqueue_tag_element_t * | pqueue_tag_find_equal_same_tag (pqueue_tag_t *q, pqueue_tag_element_t *e) |
Return an item with the same tag (cmppri returns 0) that matches the supplied element (eqelem returns non-zero) or NULL if there is none. | |
int | pqueue_tag_insert_if_no_match (pqueue_tag_t *q, tag_t t) |
Insert a tag into the queue if the tag is not already in the queue. | |
pqueue_tag_element_t * | pqueue_tag_peek (pqueue_tag_t *q) |
Return highest-ranking item (the one with the least tag) without removing it. | |
tag_t | pqueue_tag_peek_tag (pqueue_tag_t *q) |
Return the least tag in the queue or FOREVER if the queue is empty. | |
pqueue_tag_element_t * | pqueue_tag_pop (pqueue_tag_t *q) |
Pop the least-tag element from the queue. | |
tag_t | pqueue_tag_pop_tag (pqueue_tag_t *q) |
Pop the least-tag element from the queue and return its tag. | |
void | pqueue_tag_remove (pqueue_tag_t *q, pqueue_tag_element_t *e) |
Remove an item from the queue. | |
void | pqueue_tag_remove_up_to (pqueue_tag_t *q, tag_t t) |
Remove items from the queue with tags up to and including the specified tag. | |
void | pqueue_tag_dump (pqueue_tag_t *q) |
Priority queue that uses tags for sorting.
int pqueue_tag_compare | ( | pqueue_pri_t | priority1, |
pqueue_pri_t | priority2 ) |
Callback comparison function for the tag-based priority queue. Return -1 if the first argument is less than second, 0 if the two arguments are the same, and 1 otherwise. This function is of type pqueue_cmp_pri_f.
priority1 | A pointer to a pqueue_tag_element_t, cast to pqueue_pri_t. |
priority2 | A pointer to a pqueue_tag_element_t, cast to pqueue_pri_t. |
void pqueue_tag_dump | ( | pqueue_tag_t * | q | ) |
Dump the queue and it's internal structure.
pqueue_tag_element_t * pqueue_tag_find_equal_same_tag | ( | pqueue_tag_t * | q, |
pqueue_tag_element_t * | e ) |
Return an item with the same tag (cmppri
returns 0) that matches the supplied element (eqelem
returns non-zero) or NULL if there is none.
q | The queue. |
e | The element. |
pqueue_tag_element_t * pqueue_tag_find_with_tag | ( | pqueue_tag_t * | q, |
tag_t | t ) |
Return the first item with the specified tag or NULL if there is none.
q | The queue. |
t | The tag. |
void pqueue_tag_free | ( | pqueue_tag_t * | q | ) |
Free all memory used by the queue including elements that are marked dynamic.
q | The queue. |
pqueue_tag_t * pqueue_tag_init | ( | size_t | initial_size | ) |
Create a priority queue sorted by tags.
The elements of the priority queue will be of type pqueue_tag_element_t. The caller should call pqueue_tag_free() when finished with the queue.
pqueue_tag_t * pqueue_tag_init_customize | ( | size_t | initial_size, |
pqueue_cmp_pri_f | cmppri, | ||
pqueue_eq_elem_f | eqelem, | ||
pqueue_print_entry_f | prt ) |
Create a priority queue that stores elements with a particular payload.
cmppri | the callback function to compare priorities |
eqelem | the callback function to check equivalence of payloads. |
prt | the callback function to print elements |
The elements of the priority queue will be of type pqueue_tag_element_t. The caller should call pqueue_tag_free() when finished with the queue.
int pqueue_tag_insert | ( | pqueue_tag_t * | q, |
pqueue_tag_element_t * | d ) |
Insert an element into the queue.
q | The queue. |
e | The element to insert. |
int pqueue_tag_insert_if_no_match | ( | pqueue_tag_t * | q, |
tag_t | t ) |
Insert a tag into the queue if the tag is not already in the queue.
This automatically creates a dynamically allocated element in the queue and ensures that if the element is still on the queue when pqueue_tag_free is called, then that memory will be freed.
q | The queue. |
t | The tag to insert. |
int pqueue_tag_insert_tag | ( | pqueue_tag_t * | q, |
tag_t | t ) |
Insert a tag into the queue.
This automatically creates a dynamically allocated element in the queue and ensures that if the element is still on the queue when pqueue_tag_free is called, then that memory will be freed.
q | The queue. |
t | The tag to insert. |
pqueue_tag_element_t * pqueue_tag_peek | ( | pqueue_tag_t * | q | ) |
Return highest-ranking item (the one with the least tag) without removing it.
q | The queue. |
tag_t pqueue_tag_peek_tag | ( | pqueue_tag_t * | q | ) |
Return the least tag in the queue or FOREVER if the queue is empty.
q | The queue. |
pqueue_tag_element_t * pqueue_tag_pop | ( | pqueue_tag_t * | q | ) |
Pop the least-tag element from the queue.
If the entry was dynamically allocated, then it is now up to the caller to ensure that it is freed. It will not be freed by pqueue_tag_free.
q | The queue. |
tag_t pqueue_tag_pop_tag | ( | pqueue_tag_t * | q | ) |
Pop the least-tag element from the queue and return its tag.
If the queue is empty, return FOREVER_TAG. This function handles freeing the element struct if it was dynamically allocated.
q | The queue. |
void pqueue_tag_remove | ( | pqueue_tag_t * | q, |
pqueue_tag_element_t * | e ) |
Remove an item from the queue.
q | The queue. |
e | The entry to remove. |
void pqueue_tag_remove_up_to | ( | pqueue_tag_t * | q, |
tag_t | t ) |
Remove items from the queue with tags up to and including the specified tag.
If the specified tag is FOREVER_TAG, then all items will be removed.
q | The queue. |
t | The specified tag. |
size_t pqueue_tag_size | ( | pqueue_tag_t * | q | ) |
Return the size of the queue.
q | The queue. |