fheap.h (856B)
1 #ifndef FHEAP_H 2 #define FHEAP_H 3 4 #include <assert.h> 5 #include <stdint.h> 6 #include <stdlib.h> 7 #include <string.h> 8 9 typedef struct fnode_struct { 10 uint64_t value; 11 void *data; 12 13 struct fnode_struct *parent; 14 struct fnode_struct *children; 15 size_t nchildren; 16 uint64_t marked; 17 18 struct fnode_struct *left; 19 struct fnode_struct *right; 20 } fnode_t; 21 22 typedef struct { 23 size_t n; 24 fnode_t *min; 25 fnode_t *head; 26 } fheap_t; 27 28 void fnode_init(fnode_t *node, const uint64_t value, void *data); 29 void fnode_clear(fnode_t *node); 30 31 void fheap_init(fheap_t *heap); 32 void fheap_clear(fheap_t *heap); 33 34 fnode_t *fheap_insert(fheap_t *heap, const uint64_t value, void *data); 35 fnode_t *fheap_extract_min_node(fheap_t *heap); 36 uint64_t fheap_extract_min(void **data, fheap_t *heap); 37 38 void fheap_decrease_value(fheap_t *heap, fnode_t *node, const uint64_t value); 39 40 #endif