File: heap.h

package info (click to toggle)
mrcal 2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 8,992 kB
  • sloc: python: 40,651; ansic: 15,632; cpp: 1,754; perl: 303; makefile: 160; sh: 99; lisp: 84
file content (48 lines) | stat: -rw-r--r-- 1,301 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
#pragma once

#ifdef __cplusplus
extern "C" {
#endif


/*
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;
} mrcal_heap_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(mrcal_heap_node_t) == 8, "mrcal_heap_node_t has expected size");
#else
_Static_assert(sizeof(mrcal_heap_node_t) == 8, "mrcal_heap_node_t has expected size");
#endif

typedef struct
{
    uint16_t* buffer; // each of these indexes an external mrcal_heap_node_t[] array, which
                      // contains the cost
    int       size;
} mrcal_heap_t;

bool     mrcal_heap_empty (mrcal_heap_t* heap, mrcal_heap_node_t* nodes);
void     mrcal_heap_push  (mrcal_heap_t* heap, mrcal_heap_node_t* nodes, uint16_t x);
uint16_t mrcal_heap_pop   (mrcal_heap_t* heap, mrcal_heap_node_t* nodes);
void     mrcal_heap_resort(mrcal_heap_t* heap, mrcal_heap_node_t* nodes);

#ifdef __cplusplus
}
#endif