![]() |
reactor-c 1.0
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 | |
| int | is_dynamic |
| Flag indicating whether this element should be freed with the queue. | |
| size_t | pos |
| Current position of this element in the priority queue. | |
| tag_t | tag |
| The tag that determines the element's priority in the queue. | |
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:
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 |
Flag indicating whether this element should be freed with the queue.
If non-zero, the element's memory will be freed when pqueue_tag_free is called on the queue. This is useful for dynamically allocated elements that should be automatically cleaned up. Set this to non-zero if the element was allocated with malloc or calloc and should be freed when the queue is freed.
| size_t pqueue_tag_element_t::pos |
Current position of this element in the priority queue.
This field is required by the priority queue implementation to track the element's position in the heap structure. It is maintained by the queue operations and should not be modified directly.
| tag_t pqueue_tag_element_t::tag |
The tag that determines the element's priority in the queue.
The queue is sorted from least tag to largest tag. This field is used as the actual priority value when the struct pointer is cast to pqueue_pri_t.