33 #ifndef LELY_UTIL_PHEAP_H_
34 #define LELY_UTIL_PHEAP_H_
41 #ifndef LELY_UTIL_PHEAP_INLINE
42 #define LELY_UTIL_PHEAP_INLINE static inline
70 NULL, NULL, NULL, NULL \
127 #define pnode_foreach(first, node) pnode_foreach_(__COUNTER__, first, node)
129 #define pnode_foreach(first, node) pnode_foreach_(__LINE__, first, node)
131 #define pnode_foreach_(n, first, node) pnode_foreach__(n, first, node)
133 #define pnode_foreach__(n, first, node) \
134 for (struct pnode *node = (first), \
135 *_pnode_next_##n = (node) ? pnode_next(node) : NULL; \
136 (node); (node) = _pnode_next_##n, \
137 _pnode_next_##n = (node) ? pnode_next(node) : NULL)
204 #define pheap_foreach(heap, node) pnode_foreach (pheap_first(heap), node)
206 LELY_UTIL_PHEAP_INLINE
void
214 LELY_UTIL_PHEAP_INLINE
struct pnode *
224 }
while ((node = node->
parent));
228 LELY_UTIL_PHEAP_INLINE
void
239 LELY_UTIL_PHEAP_INLINE
int
245 LELY_UTIL_PHEAP_INLINE
size_t
253 LELY_UTIL_PHEAP_INLINE
struct pnode *
This header file is part of the Lely libraries; it contains the compiler feature definitions.
int pheap_contains(const struct pheap *heap, const struct pnode *node)
Checks if a node is part of a pairing heap.
struct pnode * pheap_first(const struct pheap *heap)
Returns a pointer to the first (minimum) node in a pairing heap.
void pheap_insert(struct pheap *heap, struct pnode *node)
Inserts a node into a pairing heap.
size_t pheap_size(const struct pheap *heap)
Returns the size (in number of nodes) of a pairing heap.
struct pnode * pheap_find(const struct pheap *heap, const void *key)
Finds a node in a pairing 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_init(struct pheap *heap, pheap_cmp_t *cmp)
Initializes a pairing heap.
struct pnode * pnode_next(const struct pnode *node)
Returns a pointer to the next node (in unspecified order) in a pairing heap.
void pheap_remove(struct pheap *heap, struct pnode *node)
Removes a node from a pairing heap.
int pheap_empty(const struct pheap *heap)
Returns 1 if the pairing heap is empty, and 0 if not.
void pnode_init(struct pnode *node, const void *key)
Initializes a node in a paring heap.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
pheap_cmp_t * cmp
A pointer to the function used to compare two keys.
struct pnode * root
A pointer to the root node of the heap.
size_t num_nodes
The number of nodes stored in the heap.
A node in a pairing heap.
struct pnode * parent
A pointer to the parent node.
struct pnode * child
A pointer to the first child node.
const void * key
A pointer to the key of this node.
struct pnode * next
A pointer to the next sibling node.