| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef PAIRINGHEAP_H |
| #define PAIRINGHEAP_H |
|
|
| #include "lib/stringinfo.h" |
|
|
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| typedef struct pairingheap_node |
| { |
| struct pairingheap_node *first_child; |
| struct pairingheap_node *next_sibling; |
| struct pairingheap_node *prev_or_parent; |
| } pairingheap_node; |
|
|
| |
| |
| |
| |
| |
| |
| #define pairingheap_container(type, membername, ptr) \ |
| (AssertVariableIsOfTypeMacro(ptr, pairingheap_node *), \ |
| AssertVariableIsOfTypeMacro(((type *) NULL)->membername, pairingheap_node), \ |
| ((type *) ((char *) (ptr) - offsetof(type, membername)))) |
|
|
| |
| |
| |
| #define pairingheap_const_container(type, membername, ptr) \ |
| (AssertVariableIsOfTypeMacro(ptr, const pairingheap_node *), \ |
| AssertVariableIsOfTypeMacro(((type *) NULL)->membername, pairingheap_node), \ |
| ((const type *) ((const char *) (ptr) - offsetof(type, membername)))) |
|
|
| |
| |
| |
| |
| typedef int (*pairingheap_comparator) (const pairingheap_node *a, |
| const pairingheap_node *b, |
| void *arg); |
|
|
| |
| |
| |
| |
| |
| |
| |
| typedef struct pairingheap |
| { |
| pairingheap_comparator ph_compare; |
| void *ph_arg; |
| pairingheap_node *ph_root; |
| } pairingheap; |
|
|
| extern pairingheap *pairingheap_allocate(pairingheap_comparator compare, |
| void *arg); |
| extern void pairingheap_free(pairingheap *heap); |
| extern void pairingheap_add(pairingheap *heap, pairingheap_node *node); |
| extern pairingheap_node *pairingheap_first(pairingheap *heap); |
| extern pairingheap_node *pairingheap_remove_first(pairingheap *heap); |
| extern void pairingheap_remove(pairingheap *heap, pairingheap_node *node); |
|
|
| #ifdef PAIRINGHEAP_DEBUG |
| extern char *pairingheap_dump(pairingheap *heap, |
| void (*dumpfunc) (pairingheap_node *node, StringInfo buf, void *opaque), |
| void *opaque); |
| #endif |
|
|
| |
| #define pairingheap_reset(h) ((h)->ph_root = NULL) |
|
|
| |
| #define pairingheap_is_empty(h) ((h)->ph_root == NULL) |
|
|
| |
| #define pairingheap_is_singular(h) \ |
| ((h)->ph_root && (h)->ph_root->first_child == NULL) |
|
|
| #endif |
|
|