Data Structures Lerax  1.1.0
Opinionated Data Structures & Algorithms
Loading...
Searching...
No Matches
pqueue.h
Go to the documentation of this file.
1
12
13#ifndef PQUEUE_H
14#define PQUEUE_H
15
16#ifndef PQUEUE_SIZE
17#define PQUEUE_SIZE 10
18#endif
19
20#ifndef PQUEUE_GROWTH_FACTOR
21#define PQUEUE_GROWTH_FACTOR 10
22#endif
23
24#include <stdbool.h>
27
31typedef struct PQueueNode {
32 int key;
33 int value; // priority
35
36
37#define HEAP_EMPTY_NODE {.key=-1, .value=-1}
38
46
57
58
62typedef struct PQueue PQueue;
63
72
81void pqueue_insert(PQueue *pq, int key, int value);
82
91
100void pqueue_update_key(PQueue *pq, int key, int value);
101
110int pqueue_get_priority(PQueue *pq, int key);
111
120
129
138
146
154
163
171
179
180#endif
PQueue * pqueue_create(PQueueType type)
Creates an empty priority queue.
void pqueue_print(PQueue *pq)
Prints the elements of a priority queue to the console.
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.
bool pqueue_is_empty(PQueue *pq)
Checks if the priority queue is empty.
Iterator * pqueue_iterator_keys(PQueue *pq)
Iterator over keys of priority queue.
Iterator * pqueue_iterator(PQueue *pq)
Iterator over nodes with (key, value) of priority queue.
void pqueue_println(PQueue *pq)
Prints the elements of a priority queue to the console, followed by a newline character.
void pqueue_update_key(PQueue *pq, int key, int value)
Update 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 extrac...
int pqueue_get_priority(PQueue *pq, int key)
Get the priority of an element in the priority queue.
int pqueue_size(PQueue *pq)
Returns the number of elements in the priority queue.
void pqueue_free(PQueue *pq)
Frees the memory allocated for a priority queue.
struct HashTable HashTable
A basic implementation of a hash table.
Definition hash-table.h:28
PQueueType
Enum for priority queue type (min or max).
Definition pqueue.h:42
@ MAX_PQUEUE
Definition pqueue.h:44
@ MIN_PQUEUE
Definition pqueue.h:43
A generic iterator struct.
Definition iterator.h:13
A node in the priority queue.
Definition pqueue.h:31
int value
Definition pqueue.h:33
int key
Definition pqueue.h:32
A priority queue implementation using a binary heap.
Definition pqueue.h:50
PQueueNode * heap
Definition pqueue.h:51
PQueueType type
Definition pqueue.h:55
HashTable * index
Definition pqueue.h:52
int size
Definition pqueue.h:53
int capacity
Definition pqueue.h:54