Files | |
| file | eg_eheap.ex.c |
| file | eg_eheap.h |
Data Structures | |
| struct | EGeHeap_t |
| Structure to hold a whole heap structure, this structure is designed so that it can grow on the fly with a low cost. More... | |
| struct | EGeHeapCn_t |
| Structure to store the information relevant to an element in the heap. More... | |
Defines | |
| #define | EG_EHEAP_DEBUG 1000 |
| Debug level for the heap. | |
| #define | EG_EHEAP_POISON UINT_MAX |
| Poison position for heap connector not in a heap. | |
| #define | EGeHeapAdd(hp, hcn) |
| Add an element to the heap. | |
| #define | EGeHeapChangeD(hp, width) |
| set the breath of the heap, this function must be called only when the heap is empty. | |
| #define | EGeHeapChangeVal(hp, hcn, new_val) |
| Change the value of an element in the heap. | |
| #define | EGeHeapCheck(hp) 0 |
| Check the integrity of the given heap. | |
| #define | EGeHeapClear(hp) |
| Clear a heap structure, and free any internal memory (not allocated by the user). | |
| #define | EGeHeapCnClear(hcn) EGlpNumClearVar((hcn)->val) |
| Free all internal memory used by this structured not allocated by the user. This function should be called after an init call, and only once. | |
| #define | EGeHeapCnInit(hcn) ({EGlpNumInitVar((hcn)->val);(hcn)->pos = EG_EHEAP_POISON;}) |
| Initialize a heap conector structure. This function will allocate any interal memory not allocated by the user, it should be called only once, or after a clear function call. | |
| #define | EGeHeapCnReset(hcn) ((hcn)->pos = EG_EHEAP_POISON) |
| Reset a heap conector to the same state as after an init call, this function is provided only for completness. | |
| #define | EGeHeapDel(hp, hcn) |
| Eliminate an element from the heap, note that the position stored in the eliminated element is reset to zero. | |
| #define | EGeHeapEmpty(hp) ((hp)->sz = 0) |
| set the number of elements in hte heap to zero. | |
| #define | EGeHeapFatherId(d, id) ((id)?(((id)-1)/(d)):0) |
| return the index of the father of the given index. | |
| #define | EGeHeapFirstChildId(d, id) ((d)*(id)+1) |
| Give the first child for a given position. | |
| #define | EGeHeapGetMin(hp) |
| get the minimum conector in the heap, if the heap is empty, return NULL. | |
| #define | EGeHeapGetMinVal(hp, number) |
| get the minimum value in the heap. | |
| #define | EGeHeapInit(hp) (*(hp) = (EGeHeap_t){0,0,0,0}) |
| Initialize a heap as an empty heap (with no space for conectors). | |
| #define | EGeHeapIsFull(hp) ({EGeHeap_t*const __EGehp = (hp); __EGehp->sz == __EGehp->max_sz;}) |
| Return one if the heap is full, zero otherwise. | |
| #define | EGeHeapResize(hp, new_sz) |
| resize the heap cn array to the given size, if the new size is zero, it is equivalent to free the internal memory, and left the heap as an empty heap with zero space. | |
| #define | EGeHeapSiftDown(hp, hcn) |
| Move an element down in the heap (position 0 is the top), this kind of operation is needed whenever we increase the value in a heap element. | |
| #define | EGeHeapSiftUp(hp, hcn) |
| move an element in the heap up in the heap (position 0 is the top, this kind of move is neded whenever we decrease the value in a heap element). | |
| #define | EGeHepReset(hp) EGeHeapInit(hp) |
| Reset the given heap as an empty heap (just as returned by the init call. | |
Typedefs | |
| typedef EGeHeap_t | EGeHeap_t |
| Structure to hold a whole heap structure, this structure is designed so that it can grow on the fly with a low cost. | |
| typedef EGeHeapCn_t | EGeHeapCn_t |
| Structure to store the information relevant to an element in the heap. | |
Functions | |
| int | eheap_parseargs (int argc, char **argv, unsigned int *d, unsigned int *ch, EGlpNum_t *v, char **file_name) |
| parse the input argumenbts for the program | |
| void | eheap_usage (char *program) |
| This program reads a list of double values from a text file and uses a heap to sort them. It also allows the user to change the value of one of the read numbers after they have been placed in the heap. The purpose of this program is to illustrate the use of the EGeHeap structure and its associated functions. display the usage message for this program. | |
| int | main (int argc, char **argv) |
| main function | |
|
|
Debug level for the heap.
Definition at line 62 of file eg_eheap.h. |
|
|
Poison position for heap connector not in a heap.
Definition at line 78 of file eg_eheap.h. |
|
|
Value: ({\
EGeHeap_t*const __EGlhp = (hp);\
EGeHeapCn_t*const __EGlcn = (hcn);\
__EGlhp->sz == __EGlhp->max_sz ? (fprintf(stderr,"Heap "#hp" is full, can't"\
" add element "#hcn), 1) : (__EGlcn->pos = __EGlhp->sz, \
__EGlhp->cn[__EGlhp->sz] = __EGlcn, __EGlhp->sz +=1, EGeHeapSiftUp(__EGlhp,__EGlcn), 0);})
Definition at line 218 of file eg_eheap.h. |
|
|
Value: set the breath of the heap, this function must be called only when the heap is empty.
Definition at line 333 of file eg_eheap.h. |
|
|
Value: ({\
(EGlpNumIsLess(new_val,(hcn)->val)) ? (EGlpNumCopy((hcn)->val,new_val),EGeHeapSiftUp(hp,hcn)) : (EGlpNumCopy((hcn)->val,new_val),EGeHeapSiftDown(hp,hcn));})
Definition at line 281 of file eg_eheap.h. |
|
|
Check the integrity of the given heap.
Definition at line 323 of file eg_eheap.h. |
|
|
Clear a heap structure, and free any internal memory (not allocated by the user).
Definition at line 143 of file eg_eheap.h. |
|
|
Free all internal memory used by this structured not allocated by the user. This function should be called after an init call, and only once.
Definition at line 100 of file eg_eheap.h. |
|
|
Initialize a heap conector structure. This function will allocate any interal memory not allocated by the user, it should be called only once, or after a clear function call.
Definition at line 86 of file eg_eheap.h. |
|
|
Reset a heap conector to the same state as after an init call, this function is provided only for completness.
Definition at line 93 of file eg_eheap.h. |
|
|
Value: ({\
EGeHeap_t*const __EGlhp = (hp);\
unsigned int const __EGlcn = (hcn)->pos;\
(hcn)->pos = EG_EHEAP_POISON;\
(__EGlhp->sz) -= 1;\
__EGlhp->cn[__EGlcn] = __EGlhp->cn[__EGlhp->sz];\
__EGlhp->cn[__EGlcn]->pos = __EGlcn;\
__EGlhp->cn[__EGlhp->sz] = 0;\
__EGlhp->sz ? EGeHeapSiftDown(__EGlhp,__EGlhp->cn[__EGlcn]):0;})
Definition at line 291 of file eg_eheap.h. |
|
|
set the number of elements in hte heap to zero.
Definition at line 123 of file eg_eheap.h. |
|
|
return the index of the father of the given index.
Definition at line 183 of file eg_eheap.h. |
|
|
Give the first child for a given position.
Definition at line 229 of file eg_eheap.h. |
|
|
Value: get the minimum conector in the heap, if the heap is empty, return NULL.
Definition at line 161 of file eg_eheap.h. |
|
|
Value: ({\
EGeHeap_t*const __EGehp = (hp);\
__EGehp->sz ? (EGlpNumCopy(number,__EGehp->cn[0]->val),0):1;})
Definition at line 151 of file eg_eheap.h. |
|
|
Initialize a heap as an empty heap (with no space for conectors).
Definition at line 129 of file eg_eheap.h. |
|
|
Return one if the heap is full, zero otherwise.
Definition at line 117 of file eg_eheap.h. |
|
|
Value: ({\
EGeHeap_t*const __EGehp = (hp);\
const unsigned int __EGehp_nsz = (new_sz);\
__EGehp->cn = EGrealloc((__EGehp->cn), __EGehp_nsz * sizeof(EGeHeapCn_t*));\
__EGehp->max_sz = __EGehp_nsz;})
Definition at line 172 of file eg_eheap.h. |
|
|
Move an element down in the heap (position 0 is the top), this kind of operation is needed whenever we increase the value in a heap element.
Definition at line 239 of file eg_eheap.h. |
|
|
Value: ({\
EGeHeap_t*const __EGehp = (hp);\
EGeHeapCn_t*const __EGecn = (hcn);\
unsigned int __EGcpos = __EGecn->pos;\
unsigned int __EGfpos = EGeHeapFatherId(__EGehp->d,__EGcpos);\
EGeHeapCn_t*__EGfcn = __EGehp->cn[__EGfpos];\
WARNINGL(EG_EHEAP_DEBUG,__EGehp->sz<=__EGcpos,"Heap Conector out of range");\
while(__EGcpos && \
EGlpNumIsLess(__EGecn->val,__EGfcn->val))\
{\
__EGfcn->pos = __EGcpos;\
__EGehp->cn[__EGcpos] = __EGfcn;\
__EGcpos = __EGfpos;\
__EGfpos = EGeHeapFatherId(__EGehp->d,__EGcpos);\
__EGfcn = __EGehp->cn[__EGfpos];\
}\
__EGecn->pos = __EGcpos;\
__EGehp->cn[__EGcpos] = __EGecn;\
0;})
Definition at line 192 of file eg_eheap.h. |
|
|
Reset the given heap as an empty heap (just as returned by the init call.
Definition at line 136 of file eg_eheap.h. |
|
|
Structure to hold a whole heap structure, this structure is designed so that it can grow on the fly with a low cost.
|
|
|
Structure to store the information relevant to an element in the heap.
|
|
||||||||||||||||||||||||||||
|
parse the input argumenbts for the program
Definition at line 63 of file eg_eheap.ex.c. Here is the call graph for this function: ![]() |
|
|
This program reads a list of double values from a text file and uses a heap to sort them. It also allows the user to change the value of one of the read numbers after they have been placed in the heap. The purpose of this program is to illustrate the use of the EGeHeap structure and its associated functions. display the usage message for this program.
Definition at line 50 of file eg_eheap.ex.c. |
|
||||||||||||
|
main function
Definition at line 111 of file eg_eheap.ex.c. Here is the call graph for this function: ![]() |
1.4.5