X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fprio_heap%2Fprio_heap.c;h=cd7098ff045bf09256297d341cb1a1d027dcff1c;hb=3d9990ac8bcbb870300869ed217b80151b52bf4e;hp=43b4e8a4d509bbda62e2f696d9b8327ae6bf003c;hpb=c462e188f3e7819c7bc74f671038cdbf36e8c3c0;p=babeltrace.git diff --git a/lib/prio_heap/prio_heap.c b/lib/prio_heap/prio_heap.c index 43b4e8a4..cd7098ff 100644 --- a/lib/prio_heap/prio_heap.c +++ b/lib/prio_heap/prio_heap.c @@ -25,18 +25,13 @@ * SOFTWARE. */ -#include +#include #include #include #include #include #include -#ifndef max_t -#define max_t(type, a, b) \ - ((type) (a) > (type) (b) ? (type) (a) : (type) (b)) -#endif - #ifdef DEBUG_HEAP void check_heap(const struct ptr_heap *heap) { @@ -102,7 +97,7 @@ int heap_set_len(struct ptr_heap *heap, size_t new_len) return 0; } -int heap_init(struct ptr_heap *heap, size_t alloc_len, +int bt_heap_init(struct ptr_heap *heap, size_t alloc_len, int gt(void *a, void *b)) { heap->ptrs = NULL; @@ -111,12 +106,12 @@ int heap_init(struct ptr_heap *heap, size_t alloc_len, heap->gt = gt; /* * Minimum size allocated is 1 entry to ensure memory allocation - * never fails within heap_replace_max. + * never fails within bt_heap_replace_max. */ return heap_grow(heap, max_t(size_t, 1, alloc_len)); } -void heap_free(struct ptr_heap *heap) +void bt_heap_free(struct ptr_heap *heap) { free(heap->ptrs); } @@ -147,7 +142,7 @@ static void heapify(struct ptr_heap *heap, size_t i) check_heap(heap); } -void *heap_replace_max(struct ptr_heap *heap, void *p) +void *bt_heap_replace_max(struct ptr_heap *heap, void *p) { void *res; @@ -165,7 +160,7 @@ void *heap_replace_max(struct ptr_heap *heap, void *p) return res; } -int heap_insert(struct ptr_heap *heap, void *p) +int bt_heap_insert(struct ptr_heap *heap, void *p) { void **ptrs; size_t pos; @@ -186,7 +181,7 @@ int heap_insert(struct ptr_heap *heap, void *p) return 0; } -void *heap_remove(struct ptr_heap *heap) +void *bt_heap_remove(struct ptr_heap *heap) { switch (heap->len) { case 0: @@ -198,10 +193,10 @@ void *heap_remove(struct ptr_heap *heap) /* Shrink, replace the current max by previous last entry and heapify */ heap_set_len(heap, heap->len - 1); /* len changed. previous last entry is at heap->len */ - return heap_replace_max(heap, heap->ptrs[heap->len]); + return bt_heap_replace_max(heap, heap->ptrs[heap->len]); } -void *heap_cherrypick(struct ptr_heap *heap, void *p) +void *bt_heap_cherrypick(struct ptr_heap *heap, void *p) { size_t pos, len = heap->len; @@ -223,11 +218,11 @@ found: return p; } -int heap_copy(struct ptr_heap *dst, struct ptr_heap *src) +int bt_heap_copy(struct ptr_heap *dst, struct ptr_heap *src) { int ret; - ret = heap_init(dst, src->alloc_len, src->gt); + ret = bt_heap_init(dst, src->alloc_len, src->gt); if (ret < 0) goto end;