| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef BINARYHEAP_H |
| #define BINARYHEAP_H |
|
|
| |
| |
| |
| |
| |
| |
| #ifdef FRONTEND |
| typedef void *bh_node_type; |
| #else |
| typedef Datum bh_node_type; |
| #endif |
|
|
| |
| |
| |
| |
| typedef int (*binaryheap_comparator) (bh_node_type a, bh_node_type b, void *arg); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| typedef struct binaryheap |
| { |
| int bh_size; |
| int bh_space; |
| bool bh_has_heap_property; |
| binaryheap_comparator bh_compare; |
| void *bh_arg; |
| bh_node_type bh_nodes[FLEXIBLE_ARRAY_MEMBER]; |
| } binaryheap; |
|
|
| extern binaryheap *binaryheap_allocate(int capacity, |
| binaryheap_comparator compare, |
| void *arg); |
| extern void binaryheap_reset(binaryheap *heap); |
| extern void binaryheap_free(binaryheap *heap); |
| extern void binaryheap_add_unordered(binaryheap *heap, bh_node_type d); |
| extern void binaryheap_build(binaryheap *heap); |
| extern void binaryheap_add(binaryheap *heap, bh_node_type d); |
| extern bh_node_type binaryheap_first(binaryheap *heap); |
| extern bh_node_type binaryheap_remove_first(binaryheap *heap); |
| extern void binaryheap_remove_node(binaryheap *heap, int n); |
| extern void binaryheap_replace_first(binaryheap *heap, bh_node_type d); |
|
|
| #define binaryheap_empty(h) ((h)->bh_size == 0) |
| #define binaryheap_size(h) ((h)->bh_size) |
| #define binaryheap_get_node(h, n) ((h)->bh_nodes[n]) |
|
|
| #endif |
|
|