/* * category: [data structure] * apply status: timerqueue * edit status: not * build status: * description: */ #ifndef HEAPUTIL_H #define HEAPUTIL_H #pragma once #include "config.h" #ifdef __cplusplus extern "C" { #endif /* array based heap helper */ #define heap_parent(x) (((x)-1)/2) #define heap_left_child(x) ((x)*2+1) #define heap_right_child(x) ((x)*2+2) /* calculate heapelement priority, this is the min heap implementation based on the priority */ typedef int (*heap_priority_cmp)(void*, void*); /** adjust up */ TOOLKIT_API void heap_up(void**arr, int arr_n, int slot, heap_priority_cmp prio_cmp); /** adjust down */ TOOLKIT_API void heap_down(void**arr, int arr_n, int slot, heap_priority_cmp prio_cmp); /** * arr must have enougth space to place obj * @param arr heap array * @param arr_n [in,out] elements in the array * @param obj object to insert * @param prio_fn get priority from object */ TOOLKIT_API void heap_push(void**arr, int *arr_n, void* obj, heap_priority_cmp prio_cmp); /** * @param arr heap array * @param arr_n [in,out] elements in the array * @param prio_fn get priority from object * @return root value from heap */ TOOLKIT_API void* heap_pop(void** arr, int *arr_n, heap_priority_cmp prio_cmp); #ifdef __cplusplus } // extern "C" { #endif #endif // HEAPUTIL_H