Loading...
Searching...
No Matches
priority_queue.h File Reference

A simple priority queue. More...

Detailed Description

A simple priority queue.

Author
Kaspar Schleiser kaspa.nosp@m.r@sc.nosp@m.hleis.nosp@m.er.d.nosp@m.e

Definition in file priority_queue.h.

#include <stddef.h>
#include <stdint.h>
+ Include dependency graph for priority_queue.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  priority_queue_node
 data type for priority queue nodes More...
 
struct  priority_queue_t
 data type for priority queues More...
 
#define PRIORITY_QUEUE_NODE_INIT   { NULL, 0, 0 }
 Static initializer for priority_queue_node_t.
 
#define PRIORITY_QUEUE_DATA_SIGNALING   (UINTPTR_MAX)
 Constant for signaling in the priority queue data member.
 
#define PRIORITY_QUEUE_INIT   { NULL }
 Static initializer for priority_queue_t.
 
typedef struct priority_queue_node priority_queue_node_t
 data type for priority queue nodes
 
static void priority_queue_node_init (priority_queue_node_t *priority_queue_node)
 Initialize a priority queue node object.
 
static void priority_queue_init (priority_queue_t *priority_queue)
 Initialize a priority queue object.
 
priority_queue_node_tpriority_queue_remove_head (priority_queue_t *root)
 remove the priority queue's head
 
void priority_queue_add (priority_queue_t *root, priority_queue_node_t *new_obj)
 insert new_obj into root based on its priority
 
void priority_queue_remove (priority_queue_t *root, priority_queue_node_t *node)
 remove node from root
 
void priority_queue_print (priority_queue_t *root)
 print the data and priority of every node in the given priority queue
 
void priority_queue_print_node (priority_queue_t *root)
 print the data, priority, and successor of a given node
 

Macro Definition Documentation

◆ PRIORITY_QUEUE_DATA_SIGNALING

#define PRIORITY_QUEUE_DATA_SIGNALING   (UINTPTR_MAX)

Constant for signaling in the priority queue data member.

Definition at line 53 of file priority_queue.h.

◆ PRIORITY_QUEUE_INIT

#define PRIORITY_QUEUE_INIT   { NULL }

Static initializer for priority_queue_t.

Definition at line 74 of file priority_queue.h.

◆ PRIORITY_QUEUE_NODE_INIT

#define PRIORITY_QUEUE_NODE_INIT   { NULL, 0, 0 }

Static initializer for priority_queue_node_t.

Definition at line 48 of file priority_queue.h.

Function Documentation

◆ priority_queue_add()

void priority_queue_add ( priority_queue_t root,
priority_queue_node_t new_obj 
)

insert new_obj into root based on its priority

The new object will be appended after objects with the same priority.

Parameters
[in,out]rootthe queue's root
[in]new_objthe object to prepend
Precondition
The queue does not already contain new_obj.

◆ priority_queue_init()

static void priority_queue_init ( priority_queue_t priority_queue)
inlinestatic

Initialize a priority queue object.

For initialization of variables use PRIORITY_QUEUE_INIT instead. Only use this function for dynamically allocated priority queues.

Parameters
[out]priority_queuepre-allocated priority_queue_t object, must not be NULL.

Definition at line 84 of file priority_queue.h.

◆ priority_queue_node_init()

static void priority_queue_node_init ( priority_queue_node_t priority_queue_node)
inlinestatic

Initialize a priority queue node object.

For initialization of variables use PRIORITY_QUEUE_NODE_INIT instead. Only use this function for dynamically allocated priority queue nodes.

Parameters
[out]priority_queue_nodepre-allocated priority_queue_node_t object, must not be NULL.

Definition at line 63 of file priority_queue.h.

◆ priority_queue_print()

void priority_queue_print ( priority_queue_t root)

print the data and priority of every node in the given priority queue

Note
requires ENABLE_DEBUG to be set to 1 for this file

◆ priority_queue_print_node()

void priority_queue_print_node ( priority_queue_t root)

print the data, priority, and successor of a given node

Note
requires ENABLE_DEBUG to be set to 1 for this file

◆ priority_queue_remove()

void priority_queue_remove ( priority_queue_t root,
priority_queue_node_t node 
)

remove node from root

Parameters
[in,out]rootthe priority queue's root
[in]nodethe node to remove

◆ priority_queue_remove_head()

priority_queue_node_t * priority_queue_remove_head ( priority_queue_t root)

remove the priority queue's head

Parameters
[out]rootthe queue's root
Returns
the old head