zabbix_log(LOG_LEVEL_CRIT, "element with key " ZBX_FS_UI64 " not found in heap for update", elem->key);
static void swap(zbx_binary_heap_t *heap, int index_1, int index_2);
static void __binary_heap_ensure_free_space(zbx_binary_heap_t *heap);
static int __binary_heap_bubble_up(zbx_binary_heap_t *heap, int index);
static int __binary_heap_bubble_down(zbx_binary_heap_t *heap, int index);
#define ARRAY_GROWTH_FACTOR 3/2
#define HAS_DIRECT_OPTION(heap) (0 != (heap->options & ZBX_BINARY_HEAP_OPTION_DIRECT))
static void swap(zbx_binary_heap_t *heap, int index_1, int index_2)
zbx_binary_heap_elem_t tmp;
tmp = heap->elems[index_1];
heap->elems[index_1] = heap->elems[index_2];
heap->elems[index_2] = tmp;
if (HAS_DIRECT_OPTION(heap))
zbx_hashmap_set(heap->key_index, heap->elems[index_1].key, index_1);
zbx_hashmap_set(heap->key_index, heap->elems[index_2].key, index_2);
static void __binary_heap_ensure_free_space(zbx_binary_heap_t *heap)
int tmp_elems_alloc = heap->elems_alloc;
else if (heap->elems_num == heap->elems_alloc)
tmp_elems_alloc = MAX(heap->elems_alloc + 1, heap->elems_alloc * ARRAY_GROWTH_FACTOR);
if (heap->elems_alloc != tmp_elems_alloc)
heap->elems = (zbx_binary_heap_elem_t *)heap->mem_realloc_func(heap->elems, tmp_elems_alloc *
sizeof(zbx_binary_heap_elem_t));
THIS_SHOULD_NEVER_HAPPEN;
heap->elems_alloc = tmp_elems_alloc;
static int __binary_heap_bubble_up(zbx_binary_heap_t *heap, int index)
if (heap->compare_func(&heap->elems[(index - 1) / 2], &heap->elems[index]) <= 0)
swap(heap, (index - 1) / 2, index);