blob: a8b0bb5b22b3d23d58c1b6624e7bbe23e0ae10f7 [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);
swissChili6575dd72021-02-28 11:31:28 -080037void heap_delete(struct min_heap *heap, int i);
swissChilie4f01992021-02-25 15:38:12 -080038void heap_insert(struct min_heap *heap, struct heap_entry e);
39void heap_decrease(struct min_heap *heap, int k, struct heap_entry to);
swissChili6575dd72021-02-28 11:31:28 -080040void heap_decrease_entry(struct min_heap *heap, struct heap_entry from,
41 struct heap_entry to);
42void heap_delete_entry(struct min_heap *heap, struct heap_entry e);
swissChilie4f01992021-02-25 15:38:12 -080043
44struct heap_entry heap_lookup_min(struct min_heap *heap, int min, bool *ok,
45 bool delete, int *i);