20#ifndef PQUEUE_GROWTH_FACTOR
21#define PQUEUE_GROWTH_FACTOR 10
37#define HEAP_EMPTY_NODE {.key=-1, .value=-1}
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