85 return (h->
count == 0);
102 for (parent = (idx - 1) / 2; idx; parent = (idx - 1) / 2) {
143 int parent,lchild,rchild;
149 for (parent = idx; rchild <= h->
count; ) {
150 lchild = (2 * idx)+1; rchild = (2 * parent) + 2;
153 if (lchild < h->count && h->
cmpr_idx
154 (h->
data, parent, lchild) == cmp_res) {
157 if (rchild < h->count && h->
cmpr_idx
158 (h->
data, parent, rchild) == cmp_res) {
183 for(idx = h->
size/2; idx >= 0; idx--) {
226 int i,n = (h->
count-1);
256 if (idx < 0 || idx >= h->
count) {
267 if (h->
cmpr(tmp, val) == cmp_res) {
286 return ((
t_heap*)h)->count;
327 printf(
"%s:%s {count: %d} {size: %d}\n[ ",h->
name,
329 for (i = 0; i < h->
size; i ++) {
t_gen heap_extract_root(t_gen d)
Extract the root from heap
t_gen heap_update_key(t_gen d, t_gen val, int idx)
heap update value of given node
void heapify(t_heap *h, int idx)
Rearrange a heap to maintain the heap property aka heapyfy_down
bool heap_full(t_gen d)
To check if heap full
void heap_insert(t_gen d, t_gen data)
Insert an element to heap
void heapify_up(t_heap *h, int idx)
Preserve heap property on insert by heapifying from bottom to root
bool heap_empty(t_gen d)
To check if heap empty
char * get_heaptype_name(e_heaptype type)
void heap_sort(t_gen d)
Heap sort the data
int heap_len(t_gen d)
heap count
void heap_build(t_gen d)
Build a heap given a array
void heap_print(t_gen d)
heap_print_info
void destroy_heap(t_gen d)
Destroy the instance of the heap
t_gen create_heap(char *name, t_gen data, int size, e_heaptype htype, t_dparams *prm)
Create an instance of heap
Contains declations of heap types, operations and structure.
e_heaptype
Types of heaps.
#define LOG_WARN(mod, fmt, args...)
#define free_mem(mem_addr)
#define get_mem(nmemb, size)
f_cmpr cmpr
Routine used for comparing two given elems of said type.
f_get_idx get_idx
Routine used for getting elem in given array index.
f_swp_idx swap_idx
Routine used for swapring elems in given array indicies.
f_cpy_idx copy_idx
Routine used for copying elems in given array indicies.
f_print print_data
Routine used for printing elem data.
f_cmp_idx cmpr_idx
Routine used for comparing elems in given array indicies.
f_update update
routine to update a key of given heap node
f_len len
routine to get heap len
f_ins insert
routine to insert elements in heap
f_vgen sort
routine to heap sort
f_print print
routine to print heap info
int size
Max Size of heap.
char * name
Stack instance name.
f_vgen build
routine to heapify
f_destroy destroy
routine to destroy
f_empty empty
routine to check if heap empty
f_full full
routine to check if heap full
e_heaptype type
Stack Type.
int count
Total elems present in heap.
f_gen extract
routine to extract min/max root element in heap
t_gen * data
Ptr to array based heap.
void * t_gen
Base Data type used for all data structure and data elements.
e_cmpr
Custom Compare function return type.