osurs  0.0.1
Macros | Functions
priority.c File Reference

Adaptable priority queue data structure. More...

#include "osurs/ds/priority.h"
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for priority.c:

Macros

#define INITIAL_CAPACITY   10
 

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.

Date
2023-01-02
Author
Merlin Unterfinger

Macro Definition Documentation

◆ INITIAL_CAPACITY

#define INITIAL_CAPACITY   10

The capacity of the priority queue.

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