osurs  0.0.1
Data Structures | Typedefs | Functions
priority.h File Reference

Adaptable priority queue data structure. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PriorityQueueNode
 A node in a priority queue. More...
 
struct  PriorityQueue
 A priority queue. More...
 

Typedefs

typedef struct PriorityQueueNode PriorityQueueNode
 A node in a priority queue. More...
 
typedef struct PriorityQueue PriorityQueue
 A priority queue. More...
 

Functions

PriorityQueuepriority_queue_create ()
 Creates a new priority queue. More...
 
PriorityQueueNodepriority_queue_add (PriorityQueue *queue, int priority, void *data)
 Adds an element to the priority queue. More...
 
void * priority_queue_peek (PriorityQueue *queue)
 Returns the data of the element at the front of the priority queue. More...
 
void * priority_queue_poll (PriorityQueue *queue)
 Removes and returns the data of the element at the front of the priority queue. More...
 
void * priority_queue_remove (PriorityQueue *queue, PriorityQueueNode *node)
 Removes a specific element from the priority queue, frees the node, and returns its data. More...
 
void priority_queue_change_priority (PriorityQueue *queue, PriorityQueueNode *node, int new_priority)
 Changes the priority of a specific element in the priority queue. More...
 
void priority_queue_free (PriorityQueue *queue)
 Frees a priority queue and all of its elements. More...
 

Detailed Description

Adaptable priority queue data structure.

This file defines an adaptable priority queue data structure and its associated functions. An adaptable priority queue is a type of priority queue that allows the priorities of its elements to be changed after they have been added to the queue, using so-called location-aware entries.

Adaptable priority queues are typically implemented using a heap data structure, where the priorities of elements are used to determine the order in which they are stored in the heap. The heap property ensures that the element with the highest priority is always at the top of the heap, making it easy to extract the highest-priority element from the queue.

Date
2023-01-02
Author
Merlin Unterfinger

Typedef Documentation

◆ PriorityQueue

typedef struct PriorityQueue PriorityQueue

A priority queue.

Note
The fields of this struct are intended for internal use only and should not be accessed directly

◆ PriorityQueueNode

A node in a priority queue.

Note
The fields of this struct are intended for internal use only and should not be accessed directly

Function Documentation

◆ priority_queue_add()

PriorityQueueNode* priority_queue_add ( PriorityQueue queue,
int  priority,
void *  data 
)

Adds an element to the priority queue.

Parameters
queueThe priority queue to add the element to
priorityThe priority of the element being added
dataThe data of the element being added
Returns
A pointer to the node in the priority queue corresponding to the added element

◆ priority_queue_change_priority()

void priority_queue_change_priority ( PriorityQueue queue,
PriorityQueueNode node,
int  new_priority 
)

Changes the priority of a specific element in the priority queue.

Parameters
queueThe priority queue
nodeThe node whose priority is being changed
new_priorityThe new priority of the node

◆ priority_queue_create()

PriorityQueue* priority_queue_create ( )

Creates a new priority queue.

Returns
A pointer to the newly created priority queue

◆ priority_queue_free()

void priority_queue_free ( PriorityQueue queue)

Frees a priority queue and all of its elements.

Parameters
queueThe priority queue to be freed

◆ priority_queue_peek()

void* priority_queue_peek ( PriorityQueue queue)

Returns the data of the element at the front of the priority queue.

Parameters
queueThe priority queue
Returns
The data of the element at the front of the queue, or NULL if the queue is empty

◆ priority_queue_poll()

void* priority_queue_poll ( PriorityQueue queue)

Removes and returns the data of the element at the front of the priority queue.

Parameters
queueThe priority queue
Returns
The data of the element at the front of the queue, or NULL if the queue is empty

◆ priority_queue_remove()

void* priority_queue_remove ( PriorityQueue queue,
PriorityQueueNode node 
)

Removes a specific element from the priority queue, frees the node, and returns its data.

Parameters
queueThe priority queue
nodeThe node to remove from the priority queue
Returns
The data of the removed node, or NULL if the queue is empty