2023-01-21 16:31:22 +01:00
|
|
|
#ifndef VIETER_HEAP
|
|
|
|
#define VIETER_HEAP
|
|
|
|
|
2023-01-22 09:40:35 +01:00
|
|
|
#include <stdint.h>
|
2023-01-21 16:31:22 +01:00
|
|
|
|
|
|
|
typedef struct vieter_heap vieter_heap;
|
|
|
|
|
|
|
|
typedef enum vieter_heap_error {
|
2023-01-22 09:40:35 +01:00
|
|
|
vieter_heap_ok = 0,
|
|
|
|
vieter_heap_empty = 1
|
2023-01-21 16:31:22 +01:00
|
|
|
} vieter_heap_error;
|
|
|
|
|
2023-01-22 12:32:47 +01:00
|
|
|
/*
|
|
|
|
* Allocate and initalize an empty heap.
|
|
|
|
*/
|
2023-01-21 16:31:22 +01:00
|
|
|
vieter_heap *vieter_heap_init();
|
|
|
|
|
2023-01-22 12:32:47 +01:00
|
|
|
/*
|
|
|
|
* Deallocate a heap.
|
|
|
|
*/
|
2023-01-21 16:31:22 +01:00
|
|
|
void vieter_heap_free(vieter_heap *heap);
|
|
|
|
|
2023-01-22 12:32:47 +01:00
|
|
|
/*
|
|
|
|
* Return how many elements are currently in the heap.
|
|
|
|
*/
|
2023-01-21 16:31:22 +01:00
|
|
|
uint64_t vieter_heap_size(vieter_heap *heap);
|
|
|
|
|
2023-01-22 12:32:47 +01:00
|
|
|
/*
|
|
|
|
* Insert a new value into the heap.
|
|
|
|
*/
|
2023-01-22 09:40:35 +01:00
|
|
|
vieter_heap_error vieter_heap_insert(vieter_heap *heap, uint64_t key,
|
|
|
|
void *data);
|
2023-01-21 16:31:22 +01:00
|
|
|
|
2023-01-22 12:32:47 +01:00
|
|
|
/*
|
|
|
|
* Remove the smallest element from the heap.
|
|
|
|
*/
|
2023-01-21 16:31:22 +01:00
|
|
|
vieter_heap_error vieter_heap_pop(void **out, vieter_heap *heap);
|
|
|
|
|
2023-01-22 12:32:47 +01:00
|
|
|
/*
|
|
|
|
* Get the smallest element in the heap without removing it.
|
|
|
|
*/
|
2023-01-21 16:31:22 +01:00
|
|
|
vieter_heap_error vieter_heap_peek(void **out, vieter_heap *heap);
|
|
|
|
|
|
|
|
#endif
|