X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fheap%2Fheap.h;h=69368a1ce7191514ed453938084dfc1adfce8add;hb=b57bf03422363dfc2f5d2aa28a5fd2062192c70e;hp=e7694a302fdff9be5c398cdf7843a4f405dbb75f;hpb=d6bee61681cf3976c9c0e47e4d73b8ce18f9d7ce;p=ccan diff --git a/ccan/heap/heap.h b/ccan/heap/heap.h index e7694a30..69368a1c 100644 --- a/ccan/heap/heap.h +++ b/ccan/heap/heap.h @@ -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) {