Source file for the binary min-heap used in the a* algorithm and floodfill algorithm. More...
#include <stddef.h>
#include <stdint.h>
#include "pathfinding/binary_heap.h"
#include "pathfinding/maze.h"
Functions | |
maze_grid_cell_t * | binary_heap_delete_min (binary_heap_t *p_heap) |
Deletes and returns the root node from the binary heap. More... | |
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. More... | |
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. More... | |
binary_heap_node_t | binary_heap_peek (binary_heap_t *p_heap) |
Peeks at the root node of the binary heap. More... | |
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. This is in effect lowers the node to the correct position. More... | |
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. This in effect raises the node to the correct position. More... | |
Source file for the binary min-heap used in the a* algorithm and floodfill algorithm.
binary_heap
to avoid name collisions, but we are liberal with the usage of either binary_heap_
or binary_heap
.maze_grid_cell_t * binary_heap_delete_min | ( | binary_heap_t * | p_heap | ) |
Deletes and returns the root node from the binary heap.
[in,out] | p_heap | Pointer to the binary min-heap. |
References binary_heapify_down(), binary_heap::p_array, binary_heap_node::p_maze_node, binary_heap_node::priority, and binary_heap::size.
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.
[in] | p_heap | Pointer to the binary heap. |
[in] | p_maze_node | Pointer to the node to be searched for. |
References binary_heap::p_array, binary_heap_node::p_maze_node, and binary_heap::size.
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.
[in,out] | p_heap | Pointer to the binary min-heap. |
[in] | p_maze_node | Pointer to the grid cell node to be inserted. |
[in] | priority | Priority of the node to be inserted. |
References binary_heapify_up(), binary_heap::capacity, DEBUG_PRINT, binary_heap::p_array, binary_heap_node::p_maze_node, binary_heap_node::priority, and binary_heap::size.
binary_heap_node_t binary_heap_peek | ( | binary_heap_t * | p_heap | ) |
Peeks at the root node of the binary heap.
[in] | p_heap | Pointer to the binary min-heap. |
References binary_heap::p_array.
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. This is in effect lowers the node to the correct position.
[in,out] | p_heap | Pointer to the binary heap. |
[in] | index | Index of the node to be heapified down. |
References binary_heap::p_array, and binary_heap_node::priority.
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. This in effect raises the node to the correct position.
[in,out] | p_heap | Pointer to the binary heap. |
[in] | index | Index of the node to be heapified up. |
References binary_heap::p_array, and binary_heap_node::priority.