#include "vieter_heap.h" #include "vieter_heap_tree.h" #include struct vieter_heap { vieter_heap_tree *tree; }; vieter_heap *vieter_heap_init() { return calloc(1, sizeof(vieter_heap)); } uint64_t vieter_heap_size(vieter_heap *heap) { uint64_t size = 0; vieter_heap_tree *tree = heap->tree; while (tree != NULL) { size |= 1 << tree->order; tree = tree->next; } return size; } void vieter_heap_free(vieter_heap *heap) {} vieter_heap_error vieter_heap_insert(vieter_heap *heap, uint64_t key, void *data) { vieter_heap_node *new_node = vieter_heap_node_init(); new_node->key = key; new_node->data = data; vieter_heap_tree *new_tree = vieter_heap_tree_init(new_node, NULL, 1); if (heap->tree == NULL) { heap->tree = new_tree; } else { heap->tree = vieter_heap_tree_merge(heap->tree, new_tree); } return vieter_heap_ok; } vieter_heap_error vieter_heap_pop(void **out, vieter_heap *heap) { return vieter_heap_ok; } vieter_heap_error vieter_heap_peek(void **out, vieter_heap *heap) { if (heap->tree == NULL) { return vieter_heap_empty; } uint64_t smallest_key; vieter_heap_tree *tree = heap->tree; while (tree != NULL) { if (tree->root->key < smallest_key) { smallest_key = tree->root->key; *out = tree->root->data; } tree = tree->next; } return vieter_heap_ok; }