priority_queue.h
Go to the documentation of this file.
/*
Copyright (C) 2024 The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/
#ifndef PRIORITY_QUEUE_H
#define PRIORITY_QUEUE_H
struct priority_queue *priority_queue_create(int init_capacity);
int priority_queue_size(struct priority_queue *pq);
int priority_queue_push(struct priority_queue *pq, void *data, double priority);
void *priority_queue_pop(struct priority_queue *pq);
void *priority_queue_peek_top(struct priority_queue *pq);
void *priority_queue_peek_at(struct priority_queue *pq, int index);
double priority_queue_get_priority_at(struct priority_queue *pq, int index);
double priority_queue_get_top_priority(struct priority_queue *pq);
int priority_queue_update_priority(struct priority_queue *pq, void *data, double new_priority);
int priority_queue_find_idx(struct priority_queue *pq, void *data);
int priority_queue_static_next(struct priority_queue *pq);
void priority_queue_base_reset(struct priority_queue *pq);
int priority_queue_base_next(struct priority_queue *pq);
void priority_queue_rotate_reset(struct priority_queue *pq);
int priority_queue_rotate_next(struct priority_queue *pq);
int priority_queue_remove(struct priority_queue *pq, int idx);
void priority_queue_delete(struct priority_queue *pq);
/* Iterate from begining to the end every time starts. */
#define PRIORITY_QUEUE_BASE_ITERATE( pq, idx, data, iter_count, iter_depth ) \
iter_count = 0; \
priority_queue_base_reset(pq); \
while ((iter_count < iter_depth) && ((idx = priority_queue_base_next(pq)) >= 0) && (data = priority_queue_peek_at(pq, idx)) && (iter_count += 1))
/* Iterate from last position, never reset. */
#define PRIORITY_QUEUE_STATIC_ITERATE( pq, idx, data, iter_count, iter_depth ) \
iter_count = 0; \
while ((iter_count < iter_depth) && ((idx = priority_queue_static_next(pq)) >= 0) && (data = priority_queue_peek_at(pq, idx)) && (iter_count += 1))
/* Iterate from last position, reset to the begining when needed. */
#define PRIORITY_QUEUE_ROTATE_ITERATE( pq, idx, data, iter_count, iter_depth ) \
iter_count = 0; \
while ((iter_count < iter_depth) && ((idx = priority_queue_rotate_next(pq)) >= 0) && (data = priority_queue_peek_at(pq, idx)) && (iter_count += 1))
#endif
priority_queue_size
int priority_queue_size(struct priority_queue *pq)
Count the elements in a priority queue.
priority_queue_pop
void * priority_queue_pop(struct priority_queue *pq)
Pop the element with the highest priority from a priority queue.
priority_queue_get_priority_at
double priority_queue_get_priority_at(struct priority_queue *pq, int index)
Get the priority of an element at a specified index.
priority_queue_push
int priority_queue_push(struct priority_queue *pq, void *data, double priority)
Push an element into a priority queue.
priority_queue_update_priority
int priority_queue_update_priority(struct priority_queue *pq, void *data, double new_priority)
Update the priority of an element in a priority queue.
priority_queue_base_next
int priority_queue_base_next(struct priority_queue *pq)
Advance the base_cursor to the next element and return the index.
priority_queue_remove
int priority_queue_remove(struct priority_queue *pq, int idx)
Remove the element with the specified index from a priority queue.
priority_queue_find_idx
int priority_queue_find_idx(struct priority_queue *pq, void *data)
Find the index of an element in a priority queue.
priority_queue_static_next
int priority_queue_static_next(struct priority_queue *pq)
Advance the static_cursor to the next element and return the index.
priority_queue_rotate_reset
void priority_queue_rotate_reset(struct priority_queue *pq)
Reset the rotate_cursor to 0.
priority_queue_base_reset
void priority_queue_base_reset(struct priority_queue *pq)
Reset the base_cursor to 0.
priority_queue_delete
void priority_queue_delete(struct priority_queue *pq)
Delete a priority queue.
priority_queue_rotate_next
int priority_queue_rotate_next(struct priority_queue *pq)
Advance the rotate_cursor to the next element and return the index.
priority_queue_peek_top
void * priority_queue_peek_top(struct priority_queue *pq)
Get the element with the highest priority from a priority queue.
priority_queue_peek_at
void * priority_queue_peek_at(struct priority_queue *pq, int index)
Get an element from a priority queue by a specified index.
priority_queue_create
struct priority_queue * priority_queue_create(int init_capacity)
Create a new priority queue.
priority_queue_get_top_priority
double priority_queue_get_top_priority(struct priority_queue *pq)
Get the priority of the top element in a priority queue.