Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
69160bc46a | |
|
|
c70b28b19f |
|
|
@ -43,24 +43,24 @@ 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 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);
|
||||
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); /* add element to heap ,but may violate heap property */
|
||||
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)
|
||||
#define binaryheap_empty(h) ((h)->bh_size == 0) /* judge whether heap is empty*/
|
||||
|
||||
#endif /* BINARYHEAP_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue