Update binaryheap.h

This commit is contained in:
zpc_gitlink 2023-09-07 16:47:34 +08:00
parent 8de0f268bd
commit c70b28b19f
1 changed files with 17 additions and 14 deletions

View File

@ -43,24 +43,27 @@ typedef int (*binaryheap_comparator)(Datum a, Datum b, void* arg);
* bh_nodes variable-length array of "space" nodes
*/
typedef struct binaryheap {
int bh_size;
int bh_space;
int bh_size; /* number of nodes currently in heap */
int bh_space; /* current size of bh_nodes array */
bool bh_has_heap_property; /* debugging cross-check */
binaryheap_comparator bh_compare;
void* bh_arg;
Datum bh_nodes[FLEXIBLE_ARRAY_MEMBER];
binaryheap_comparator bh_compare; /* comparison function */
void* bh_arg; /* extra argument for comparison function */
Datum bh_nodes[FLEXIBLE_ARRAY_MEMBER]; /* VARIABLE LENGTH ARRAY */
} 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 binaryheap* binaryheap_allocate(int capacity, binaryheap_comparator compare, void* arg); /* allocates memory */
extern void binaryheap_reset(binaryheap* heap); /* reset heap, but not free memory*/
extern void binaryheap_free(binaryheap* heap); /* frees memory */
extern void binaryheap_add_unordered(binaryheap* heap, Datum d);
extern void binaryheap_build(binaryheap* heap);
extern void binaryheap_add(binaryheap* heap, Datum d);
extern Datum binaryheap_first(binaryheap* heap);
extern Datum binaryheap_remove_first(binaryheap* heap);
extern void binaryheap_replace_first(binaryheap* heap, Datum d);
/* add element to heap ,but may violate heap property */
#define binaryheap_empty(h) ((h)->bh_size == 0)
extern void binaryheap_build(binaryheap* heap); /* builds heap property */
extern void binaryheap_add(binaryheap* heap, Datum d); /*add element to heap*/
extern Datum binaryheap_first(binaryheap* heap); /* returns first element */
extern Datum binaryheap_remove_first(binaryheap* heap); /* removes first element */
extern void binaryheap_replace_first(binaryheap* heap, Datum d); /* replaces first element */
#define binaryheap_empty(h) ((h)->bh_size == 0) /* judge whether heap is empty*/
#endif /* BINARYHEAP_H */