-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathheap.h
39 lines (32 loc) · 1.09 KB
/
heap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
/*
A simple min-priority-queue implementation. Uses STL internally
This is for the most part an internal implementation detail of
mrcal_traverse_sensor_links(), but could potentially be useful somewhere
on its own, so I'm exposing it here
*/
#include <stdint.h>
#include <stdbool.h>
typedef struct
{
uint16_t idx_parent;
bool done : 1;
uint64_t cost : 47;
} node_t;
// I can't find a single static assertion invocation that works in both C++ and
// C. The below is ugly, but works
#ifdef __cplusplus
static_assert( sizeof(node_t) == 8, "node_t has expected size");
#else
_Static_assert(sizeof(node_t) == 8, "node_t has expected size");
#endif
typedef struct
{
uint16_t* buffer; // each of these indexes an external node_t[] array, which
// contains the cost
int size;
} mrcal_heap_t;
bool mrcal_heap_empty (mrcal_heap_t* heap, node_t* nodes);
void mrcal_heap_push (mrcal_heap_t* heap, node_t* nodes, uint16_t x);
uint16_t mrcal_heap_pop (mrcal_heap_t* heap, node_t* nodes);
void mrcal_heap_resort(mrcal_heap_t* heap, node_t* nodes);