33 #ifndef LELY_UTIL_PHEAP_H_ 34 #define LELY_UTIL_PHEAP_H_ 40 #ifndef LELY_UTIL_PHEAP_INLINE 41 #define LELY_UTIL_PHEAP_INLINE static inline 69 NULL, NULL, NULL, NULL \ 126 #define pnode_foreach(first, node) pnode_foreach_(__COUNTER__, first, node) 128 #define pnode_foreach(first, node) pnode_foreach_(__LINE__, first, node) 130 #define pnode_foreach_(n, first, node) pnode_foreach__(n, first, node) 132 #define pnode_foreach__(n, first, node) \ 133 for (struct pnode *node = (first), \ 134 *_pnode_next_##n = (node) ? pnode_next(node) : NULL; \ 135 (node); (node) = _pnode_next_##n, \ 136 _pnode_next_##n = (node) ? pnode_next(node) : NULL) 193 #define pheap_foreach(heap, node) pnode_foreach (pheap_first(heap), node) 201 inline struct pnode *
209 }
while ((node = node->
parent));
233 inline struct pnode *
243 #endif // !LELY_UTIL_PHEAP_H_ void pnode_init(struct pnode *node, const void *key)
Initializes a node in a paring heap.
struct pnode * pheap_find(const struct pheap *heap, const void *key)
Finds a node in a pairing heap.
int pheap_empty(const struct pheap *heap)
Returns 1 if the pairing heap is empty, and 0 if not.
struct pnode * pnode_next(const struct pnode *node)
Returns a pointer to the next node (in unspecified order) in a pairing heap.
size_t pheap_size(const struct pheap *heap)
Returns the size (in number of nodes) of a pairing heap.
pheap_cmp_t * cmp
A pointer to the function used to compare two keys.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef.h> and defines any missing functionality.
void pheap_insert(struct pheap *heap, struct pnode *node)
Inserts a node into a pairing heap.
size_t num_nodes
The number of nodes stored in the heap.
struct pnode * root
A pointer to the root node of the heap.
int pheap_cmp_t(const void *p1, const void *p2)
The type of a comparison function suitable for use in a paring heap.
void pheap_remove(struct pheap *heap, struct pnode *node)
Removes a node from a pairing heap.
const void * key
A pointer to the key of this node.
struct pnode * child
A pointer to the first child node.
This header file is part of the Lely libraries; it contains the compiler feature definitions.
struct pnode * pheap_first(const struct pheap *heap)
Returns a pointer to the first (minimum) node in a pairing heap.
void pheap_init(struct pheap *heap, pheap_cmp_t *cmp)
Initializes a pairing heap.
struct pnode * next
A pointer to the next sibling node.
struct pnode * parent
A pointer to the parent node.
A node in a pairing heap.