@web-font-path: "roboto-debian.css";
Loading...
Searching...
No Matches
pheap.h File Reference
#include "pico.h"
Include dependency graph for pheap.h:

Go to the source code of this file.

Data Structures

struct  pheap_node
struct  pheap

Macros

#define PARAM_ASSERTIONS_ENABLED_PHEAP   0
#define PICO_PHEAP_MAX_ENTRIES   255
#define PHEAP_DEFINE_STATIC(name, _max_nodes)
 Define a statically allocated pairing heap. This must be initialized by ph_post_alloc_init.

Typedefs

typedef uint8_t pheap_node_id_t
typedef struct pheap_node pheap_node_t
typedef bool(* pheap_comparator) (void *user_data, pheap_node_id_t a, pheap_node_id_t b)
 A user comparator function for nodes in a pairing heap.
typedef struct pheap pheap_t

Functions

pheap_t * ph_create (uint max_nodes, pheap_comparator comparator, void *user_data)
 Create a pairing heap, which effectively maintains an efficient sorted ordering of nodes. The heap itself stores no user per-node state, it is expected that the user maintains a companion array. A comparator function must be provided so that the heap implementation can determine the relative ordering of nodes.
void ph_clear (pheap_t *heap)
 Removes all nodes from the pairing heap.
void ph_destroy (pheap_t *heap)
 De-allocates a pairing heap.
static pheap_node_t * ph_get_node (pheap_t *heap, pheap_node_id_t id)
static void ph_add_child_node (pheap_t *heap, pheap_node_id_t parent_id, pheap_node_id_t child_id)
static pheap_node_id_t ph_merge_nodes (pheap_t *heap, pheap_node_id_t a, pheap_node_id_t b)
static pheap_node_id_t ph_new_node (pheap_t *heap)
 Allocate a new node from the unused space in the heap.
static pheap_node_id_t ph_insert_node (pheap_t *heap, pheap_node_id_t id)
 Inserts a node into the heap.
static pheap_node_id_t ph_peek_head (pheap_t *heap)
 Returns the head node in the heap, i.e. the node which compares first, but without removing it from the heap.
pheap_node_id_t ph_remove_head (pheap_t *heap, bool free)
 Remove the head node from the pairing heap. This head node is the node which compares first in the logical ordering provided by the comparator.
static pheap_node_id_t ph_remove_and_free_head (pheap_t *heap)
 Remove the head node from the pairing heap. This head node is the node which compares first in the logical ordering provided by the comparator.
bool ph_remove_and_free_node (pheap_t *heap, pheap_node_id_t id)
 Remove and free an arbitrary node from the pairing heap. This is a more costly operation than removing the head via ph_remove_and_free_head().
static bool ph_contains_node (pheap_t *heap, pheap_node_id_t id)
 Determine if the heap contains a given node. Note containment refers to whether the node is inserted (ph_insert_node()) vs allocated (ph_new_node()).
static void ph_free_node (pheap_t *heap, pheap_node_id_t id)
 Free a node that is not currently in the heap, but has been allocated.
void ph_dump (pheap_t *heap, void(*dump_key)(pheap_node_id_t id, void *user_data), void *user_data)
 Print a representation of the heap for debugging.
void ph_post_alloc_init (pheap_t *heap, uint max_nodes, pheap_comparator comparator, void *user_data)
 Initialize a statically allocated heap (ph_create() using the C heap). The heap member nodes must be allocated of size max_nodes.