INF2004-Project v0.1
 
Loading...
Searching...
No Matches
binary_heap.h
Go to the documentation of this file.
1
12#ifndef BINARY_HEAP_H
13#define BINARY_HEAP_H
14
15#include <stdint.h>
16#include "pathfinding/maze.h"
17
18// Definitions.
19// ----------------------------------------------------------------------------
20//
21
22#ifndef NDEBUG
23#include <stdio.h>
24
31#define DEBUG_PRINT(...) printf(__VA_ARGS__)
32#else
33#define DEBUG_PRINT(...)
34#endif
35
36// Type definitions.
37// ----------------------------------------------------------------------------
38//
39
44typedef struct binary_heap_node
45{
46 uint16_t priority;
49
51
58typedef struct binary_heap
59{
61 uint16_t capacity;
63
64 uint16_t size;
66
67// Public functions.
68// ----------------------------------------------------------------------------
69//
70
71void binary_heapify_up(binary_heap_t *p_heap, uint16_t index);
72
73void binary_heapify_down(binary_heap_t *p_heap, uint16_t index);
74
76 maze_grid_cell_t *p_maze_node,
77 uint16_t priority);
78
80
82
83uint16_t binary_heap_get_node_idx(const binary_heap_t *p_heap,
84 const maze_grid_cell_t *p_maze_node);
85
86#endif // BINARY_HEAP_H
87
88// End of pathfinding/binary_heap.h
void binary_heapify_up(binary_heap_t *p_heap, uint16_t index)
Moves the node at the given index down the binary heap to maintain the heap property....
Definition: binary_heap.c:32
uint16_t binary_heap_get_node_idx(const binary_heap_t *p_heap, const maze_grid_cell_t *p_maze_node)
Finds the index of a given node in the binary heap if it exists. Otherwise, returns UINT16_MAX.
Definition: binary_heap.c:232
struct binary_heap binary_heap_t
Struct containing the binary heap.
struct binary_heap_node binary_heap_node_t
This struct contains basic information about a node in a priority queue implemented with a binary hea...
binary_heap_node_t binary_heap_peek(binary_heap_t *p_heap)
Peeks at the root node of the binary heap.
Definition: binary_heap.c:216
void binary_heap_insert(binary_heap_t *p_heap, maze_grid_cell_t *p_maze_node, uint16_t priority)
Inserts a grid cell node into the binary heap with a given priority.
Definition: binary_heap.c:147
void binary_heapify_down(binary_heap_t *p_heap, uint16_t index)
Moves the node at the given index up the binary heap to maintain the heap property....
Definition: binary_heap.c:88
maze_grid_cell_t * binary_heap_delete_min(binary_heap_t *p_heap)
Deletes and returns the root node from the binary heap.
Definition: binary_heap.c:183
Header file for the maze data structure and public functions.
This struct contains basic information about a node in a priority queue implemented with a binary hea...
Definition: binary_heap.h:45
uint16_t priority
Definition: binary_heap.h:46
maze_grid_cell_t * p_maze_node
Pointer to a node in the maze.
Definition: binary_heap.h:48
Struct containing the binary heap.
Definition: binary_heap.h:59
binary_heap_node_t * p_array
Pointer to the first element of the array.
Definition: binary_heap.h:60
uint16_t capacity
Definition: binary_heap.h:61
uint16_t size
Current number of nodes in the binary heap.
Definition: binary_heap.h:64
This struct contains the node information.
Definition: maze.h:91