reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
pqueue_tag.h File Reference
#include "pqueue_base.h"
#include "tag.h"

Go to the source code of this file.

Data Structures

struct  pqueue_tag_element_t
 The type for an element in a priority queue that is sorted by tag. More...
 

Typedefs

typedef pqueue_t pqueue_tag_t
 Type of a priority queue sorted by tags.
 

Functions

pqueue_tag_tpqueue_tag_init (size_t initial_size)
 Create a priority queue sorted by tags.
 
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.
 
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_tpqueue_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_tpqueue_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_tpqueue_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.
 

Typedef Documentation

◆ pqueue_tag_t

Type of a priority queue sorted by tags.

Function Documentation

◆ pqueue_tag_find_with_tag()

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.

Parameters
qThe queue.
tThe tag.
Returns
An entry with the specified tag or NULL if there isn't one.

◆ pqueue_tag_free()

void pqueue_tag_free ( pqueue_tag_t * q)

Free all memory used by the queue including elements that are marked dynamic.

Parameters
qThe queue.

◆ pqueue_tag_init()

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.

Returns
A dynamically allocated priority queue or NULL if memory allocation fails.

◆ pqueue_tag_insert()

int pqueue_tag_insert ( pqueue_tag_t * q,
pqueue_tag_element_t * d )

Insert an element into the queue.

Parameters
qThe queue.
eThe element to insert.
Returns
0 on success

◆ pqueue_tag_insert_if_no_match()

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.

Parameters
qThe queue.
tThe tag to insert.
Returns
0 on success, 1 otherwise.

◆ pqueue_tag_insert_tag()

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.

Parameters
qThe queue.
tThe tag to insert.
Returns
0 on success

◆ pqueue_tag_peek()

pqueue_tag_element_t * pqueue_tag_peek ( pqueue_tag_t * q)

Return highest-ranking item (the one with the least tag) without removing it.

Parameters
qThe queue.
Returns
NULL on if the queue is empty, otherwise the entry.

◆ pqueue_tag_peek_tag()

tag_t pqueue_tag_peek_tag ( pqueue_tag_t * q)

Return the least tag in the queue or FOREVER if the queue is empty.

Parameters
qThe queue.
Returns
The least tag in the queue or FOREVER if the queue is empty.

◆ pqueue_tag_pop()

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.

Parameters
qThe queue.
Returns
NULL on error, otherwise the entry

◆ pqueue_tag_pop_tag()

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.

Parameters
qThe queue.
Returns
NULL on error, otherwise the entry

◆ pqueue_tag_remove()

void pqueue_tag_remove ( pqueue_tag_t * q,
pqueue_tag_element_t * e )

Remove an item from the queue.

Parameters
qThe queue.
eThe entry to remove.

◆ pqueue_tag_remove_up_to()

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.

Parameters
qThe queue.
tThe specified tag.

◆ pqueue_tag_size()

size_t pqueue_tag_size ( pqueue_tag_t * q)

Return the size of the queue.

Parameters
qThe queue.