Data Structures Lerax  1.1.0
Opinionated Data Structures & Algorithms
Loading...
Searching...
No Matches
pqueue.h File Reference
#include <stdbool.h>
#include "../iterator/iterator.h"
#include "../hash-table/hash-table.h"

Go to the source code of this file.

Data Structures

struct  PQueueNode
 A node in the priority queue. More...
struct  PQueue
 A priority queue implementation using a binary heap. More...

Macros

#define PQUEUE_SIZE   10
#define PQUEUE_GROWTH_FACTOR   10
#define HEAP_EMPTY_NODE   {.key=-1, .value=-1}

Typedefs

typedef struct PQueueNode PQueueNode
 A node in the priority queue.
typedef enum PQueueType PQueueType
 Enum for priority queue type (min or max).
typedef struct PQueue PQueue
 A priority queue.

Enumerations

enum  PQueueType { MIN_PQUEUE , MAX_PQUEUE }
 Enum for priority queue type (min or max). More...

Functions

PQueuepqueue_create (PQueueType type)
 Creates an empty priority queue.
void pqueue_insert (PQueue *pq, int key, int value)
 Inserts an element into the priority queue.
PQueueNode pqueue_extract (PQueue *pq)
 Extracts the top element (max for MAX_PQUEUE, min for MIN_PQUEUE) from the priority queue.
void pqueue_update_key (PQueue *pq, int key, int value)
 Update the priority of an element in the priority queue.
int pqueue_get_priority (PQueue *pq, int key)
 Get the priority of an element in the priority queue.
PQueueNode pqueue_top (PQueue *pq)
 Returns the top element (max for MAX_PQUEUE, min for MIN_PQUEUE) in the priority queue without extracting it.
int pqueue_size (PQueue *pq)
 Returns the number of elements in the priority queue.
bool pqueue_is_empty (PQueue *pq)
 Checks if the priority queue is empty.
void pqueue_free (PQueue *pq)
 Frees the memory allocated for a priority queue.
void pqueue_print (PQueue *pq)
 Prints the elements of a priority queue to the console.
void pqueue_println (PQueue *pq)
 Prints the elements of a priority queue to the console, followed by a newline character.
Iteratorpqueue_iterator_keys (PQueue *pq)
 Iterator over keys of priority queue.
Iteratorpqueue_iterator (PQueue *pq)
 Iterator over nodes with (key, value) of priority queue.

Macro Definition Documentation

◆ HEAP_EMPTY_NODE

#define HEAP_EMPTY_NODE   {.key=-1, .value=-1}

◆ PQUEUE_GROWTH_FACTOR

#define PQUEUE_GROWTH_FACTOR   10

◆ PQUEUE_SIZE

#define PQUEUE_SIZE   10

    Copyright 2017-2025 Manoel Vilela

    Author: Manoel Vilela
   Contact: manoel_vilela@engineer.com

Organization: UFC


Typedef Documentation

◆ PQueue

typedef struct PQueue PQueue

A priority queue.

◆ PQueueNode

typedef struct PQueueNode PQueueNode

A node in the priority queue.

◆ PQueueType

typedef enum PQueueType PQueueType

Enum for priority queue type (min or max).

Enumeration Type Documentation

◆ PQueueType

enum PQueueType

Enum for priority queue type (min or max).

Enumerator
MIN_PQUEUE 
MAX_PQUEUE