reactor-c
C Runtime for Lingua Franca
|
The type for an element in a priority queue that is sorted by tag. More...
#include <pqueue_tag.h>
Data Fields | |
tag_t | tag |
size_t | pos |
int | is_dynamic |
The type for an element in a priority queue that is sorted by tag.
In this design, a pointer to this struct is also a "priority" (it can be cast to pqueue_pri_t). The actual priority is the tag field of the struct, in that the queue is sorted from least tag to largest.
If your struct is dynamically allocated using malloc or calloc, and you would like the memory freed when the queue is freed, then set the is_dynamic field of the element to a non-zero value.
For a priority queue that contains only tags with no payload, you can avoid creating the element struct by using the functions pqueue_tag_insert_tag, pqueue_tag_insert_if_no_match, and pqueue_tag_pop_tag.
To customize the element you put onto the queue, for example to carry a payload, you can create your own element struct type by simply declaring the first field to be a pqueue_tag_element_t. For example, if you want an element of the queue to include a pointer to your own payload, you can declare the following struct type:
typedef struct { pqueue_tag_element_t base; my_type* my_payload; } my_element_type_t;
When inserting your struct into the queue, simply cast your pointer to (pqueue_tag_element_t*). When accessing your struct from the queue, simply cast the result to (my_element_type_t*);
int pqueue_tag_element_t::is_dynamic |
size_t pqueue_tag_element_t::pos |
tag_t pqueue_tag_element_t::tag |