|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
#include "serene/rt/impl/pqmh.h"#include "serene/rt/context.h"#include "serene/rt/engine.h"#include "serene/rt/mm/interface.h"#include "serene/utils.h"Go to the source code of this file.
Macros | |
| #define | PQMH_MIN_CAP 8U |
| Capacity a queue created with initial_cap == 0 starts at. | |
Functions | |
| static void | sift_up (srn_context_t *ctx, pqmh_t *pq, size_t i) |
| Move the element at i up toward the root until the heap order holds (its parent is no longer ordered after it). | |
| static void | sift_down (srn_context_t *ctx, pqmh_t *pq, size_t i) |
| Move the element at i down toward the leaves until the heap order holds (neither child is ordered before it). | |
| pqmh_t | pqmh_make (srn_context_t *ctx, const pqmh_control_t *ctl, size_t initial_cap) |
| Create an empty queue ordered by ctl, with room for initial_cap elements (a small default is used when 0). | |
| void | pqmh_push (srn_context_t *ctx, pqmh_t *pq, void *elem) |
| Insert elem, growing the backing array (doubling) if it is full. | |
| bool | pqmh_pop (srn_context_t *ctx, pqmh_t *pq, void **out) |
| Remove the highest priority element into *out and return true, or return false (leaving *out untouched) when the queue is empty. | |
| void * | pqmh_peek (const pqmh_t *pq) |
| The highest priority element without removing it, or NULL when the queue is empty. | |
| size_t | pqmh_len (const pqmh_t *pq) |
| The number of elements currently in the queue. | |
| void | pqmh_free (srn_context_t *ctx, pqmh_t *pq) |
| Release the backing array and reset the queue to empty. | |
| #define PQMH_MIN_CAP 8U |
| void pqmh_free | ( | srn_context_t * | ctx, |
| pqmh_t * | pq ) |
Release the backing array and reset the queue to empty.
The elements themselves are not touched – their lifetime belongs to the caller.
Definition at line 142 of file pqmh.c.
|
nodiscard |
|
nodiscard |
Create an empty queue ordered by ctl, with room for initial_cap elements (a small default is used when 0).
The backing array comes from the manual allocator, so the queue must later be released with pqmh_free.
Definition at line 81 of file pqmh.c.
|
nodiscard |
|
nodiscard |
Remove the highest priority element into *out and return true, or return false (leaving *out untouched) when the queue is empty.
Definition at line 111 of file pqmh.c.
| void pqmh_push | ( | srn_context_t * | ctx, |
| pqmh_t * | pq, | ||
| void * | elem ) |
Insert elem, growing the backing array (doubling) if it is full.
Panics if the growth allocation fails.
Definition at line 92 of file pqmh.c.
|
static |
Move the element at i down toward the leaves until the heap order holds (neither child is ordered before it).
Definition at line 56 of file pqmh.c.
|
static |
Move the element at i up toward the root until the heap order holds (its parent is no longer ordered after it).
Definition at line 36 of file pqmh.c.