blob: bc42620bc20a3e3999017f037773d0f5d0772385 [file] [log] [blame]
swissChilie4f01992021-02-25 15:38:12 -08001#pragma once
2
3#include "kint.h"
4
5#define HEAP_SIZE 4096
6#define HEAP_MAGIC 0xCAFEBABE
7
8struct heap_entry
9{
10 uint key;
11 size_t address;
12};
13
14struct min_heap
15{
16 struct heap_entry elements[HEAP_SIZE];
17 uint size;
18};
19
20struct heap_alloc_header
21{
22 uint magic;
23 bool allocated;
24 // size = size from beginning of header to end of footer
25 size_t size;
26};
27
28struct heap_alloc_footer
29{
30 // size = size from beginning of header to end of footer
31 size_t size;
32};
33
34int heap_parent(int i);
35int heap_left(int i);
36int heap_right(int i);
37void heap_delete(struct min_heap *heap, int k);
38void heap_insert(struct min_heap *heap, struct heap_entry e);
39void heap_decrease(struct min_heap *heap, int k, struct heap_entry to);
40
41struct heap_entry heap_lookup_min(struct min_heap *heap, int min, bool *ok,
42 bool delete, int *i);