/*
- * Static-sized priority heap containing pointers. Based on CLRS,
- * chapter 6.
- *
- * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * SPDX-License-Identifier: MIT
*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * Copyright 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*
- * 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.
+ * Static-sized priority heap containing pointers. Based on CLRS,
+ * chapter 6.
*/
-#include "common/babeltrace.h"
+#include "common/macros.h"
#include "common/assert.h"
#include <errno.h>
#include <stdlib.h>
return;
for (i = 1; i < heap->len; i++)
- BT_ASSERT(!heap->gt(heap->ptrs[i], heap->ptrs[0]));
+ BT_ASSERT_DBG(!heap->gt(heap->ptrs[i], heap->ptrs[0]));
}
#endif
{
void **new_ptrs;
- if (likely(heap->alloc_len >= new_len))
+ if (G_LIKELY(heap->alloc_len >= new_len))
return 0;
- heap->alloc_len = max_t(size_t, new_len, heap->alloc_len << 1);
+ heap->alloc_len = bt_max_t(size_t, new_len, heap->alloc_len << 1);
new_ptrs = calloc(heap->alloc_len, sizeof(void *));
- if (unlikely(!new_ptrs))
+ if (G_UNLIKELY(!new_ptrs))
return -ENOMEM;
- if (likely(heap->ptrs))
+ if (G_LIKELY(heap->ptrs))
memcpy(new_ptrs, heap->ptrs, heap->len * sizeof(void *));
free(heap->ptrs);
heap->ptrs = new_ptrs;
int ret;
ret = heap_grow(heap, new_len);
- if (unlikely(ret))
+ if (G_UNLIKELY(ret))
return ret;
heap->len = new_len;
return 0;
* Minimum size allocated is 1 entry to ensure memory allocation
* never fails within bt_heap_replace_max.
*/
- return heap_grow(heap, max_t(size_t, 1, alloc_len));
+ return heap_grow(heap, bt_max_t(size_t, 1, alloc_len));
}
void bt_heap_free(struct ptr_heap *heap)
largest = i;
if (r < heap->len && heap->gt(ptrs[r], ptrs[largest]))
largest = r;
- if (unlikely(largest == i))
+ if (G_UNLIKELY(largest == i))
break;
tmp = ptrs[i];
ptrs[i] = ptrs[largest];
{
void *res;
- if (unlikely(!heap->len)) {
+ if (G_UNLIKELY(!heap->len)) {
(void) heap_set_len(heap, 1);
heap->ptrs[0] = p;
check_heap(heap);
int ret;
ret = heap_set_len(heap, heap->len + 1);
- if (unlikely(ret))
+ if (G_UNLIKELY(ret))
return ret;
ptrs = heap->ptrs;
pos = heap->len - 1;
size_t pos, len = heap->len;
for (pos = 0; pos < len; pos++)
- if (unlikely(heap->ptrs[pos] == p))
+ if (G_UNLIKELY(heap->ptrs[pos] == p))
goto found;
return NULL;
found:
- if (unlikely(heap->len == 1)) {
+ if (G_UNLIKELY(heap->len == 1)) {
(void) heap_set_len(heap, 0);
check_heap(heap);
return heap->ptrs[0];