X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=include%2Fbabeltrace%2Fprio_heap.h;h=90aec8f8cacd976edb08a0ec06b404da2a677ccc;hp=51cdac56c26d693a9a655f2318c8b81d3e2c67b8;hb=c462e188f3e7819c7bc74f671038cdbf36e8c3c0;hpb=1eb0c69cf759f535b1a926e667ae3f3aed486c9f diff --git a/include/babeltrace/prio_heap.h b/include/babeltrace/prio_heap.h index 51cdac56..90aec8f8 100644 --- a/include/babeltrace/prio_heap.h +++ b/include/babeltrace/prio_heap.h @@ -18,9 +18,18 @@ * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ #include +#include struct ptr_heap { size_t len, alloc_len; @@ -28,6 +37,15 @@ struct ptr_heap { int (*gt)(void *a, void *b); }; +#ifdef DEBUG_HEAP +void check_heap(const struct ptr_heap *heap); +#else +static inline +void check_heap(const struct ptr_heap *heap) +{ +} +#endif + /** * heap_maximum - return the largest element in the heap * @heap: the heap to be operated on @@ -37,7 +55,8 @@ struct ptr_heap { */ static inline void *heap_maximum(const struct ptr_heap *heap) { - return heap->len ? heap->ptrs[0] : NULL; + check_heap(heap); + return likely(heap->len) ? heap->ptrs[0] : NULL; } /** @@ -103,4 +122,13 @@ extern void *heap_cherrypick(struct ptr_heap *heap, void *p); */ extern void *heap_replace_max(struct ptr_heap *heap, void *p); +/** + * heap_copy - copy a heap + * @dst: the destination heap (must be allocated) + * @src: the source heap + * + * Returns -ENOMEM if out of memory. + */ +extern int heap_copy(struct ptr_heap *dst, struct ptr_heap *src); + #endif /* _BABELTRACE_PRIO_HEAP_H */