Commit 03d339d5 authored by Emilio G. Cota's avatar Emilio G. Cota

heap: add example on empty heap check

Suggested-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarEmilio G. Cota <cota@braap.org>
parent 60465a3c
......@@ -88,7 +88,8 @@ int heap_push(struct heap *h, void *data);
*
* Returns the root entry of the heap after extracting it, or NULL on error.
*
* Note: Calling heap_pop() on an empty heap is a bug--don't do it.
* Note: Calling heap_pop() on an empty heap is a bug. When in doubt,
* check heap->len. See heap_peek()'s documentation for an example.
*
* Complexity: O(log n)
*
......@@ -102,9 +103,16 @@ void *heap_pop(struct heap *h);
*
* Returns the root entry in the heap, without extracting it from @h.
*
* Note: Calling heap_peek() on an empty heap is a bug--don't do it.
* Note: Calling heap_peek() on an empty heap is a bug; check the heap's
* number of items and act accordingly, as in the example below.
*
* See also: heap_pop()
*
* Example:
* static inline void *heap_peek_safe(const struct heap *h)
* {
* return h->len ? heap_peek(h) : NULL;
* }
*/
static inline void *heap_peek(const struct heap *h)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment