Elektra
0.8.18
|
The Vheap structure. More...
Functions | |
Vheap * | elektraVheapInit (VheapComp comp, size_t minSize) |
Allocates vheap with size specified by parameter minSize. More... | |
int | elektraVheapIsEmpty (const Vheap *vheap) |
Checks if the heap is empty. More... | |
void | elektraVheapDel (Vheap *vheap) |
Deletes the heap, by freeing all the memory. | |
int | elektraVheapInsert (Vheap *vheap, void *data) |
Inserts an element in the Vheap, by finding the right position. More... | |
void * | elektraVheapRemove (Vheap *vheap) |
Removes and returns an element from the Vheap, by taking the first element which is ordered by VheapComp, after removal the remaining elements get ordered again. More... | |
int | elektraVheapClear (Vheap *vheap) |
Clears the heap in a fast fashion. More... | |
The Vheap structure.
A heap is a Data structure which keeps the data ordered. Elements can only be retrieved in this order! Insertions and retrieves need log (n).
This implementation allocates memory dynamically. The space gets doubled if full and reduced by half if used only a quarter of it, but not less than minSize.
To construct a max heap the comparison function VheapComp (a, b), must return 1 on a > b and 0 otherwise. For a min heap 1 on a < b and 0 otherwise.
int elektraVheapClear | ( | Vheap * | vheap | ) |
Clears the heap in a fast fashion.
Set the count to zero and does not reallocate memory. The next reallocation happens at Remove.
1 | on success |
0 | on error |
Vheap* elektraVheapInit | ( | VheapComp | comp, |
size_t | minSize | ||
) |
Allocates vheap with size specified by parameter minSize.
To construct a max heap the comparison function VheapComp (a, b), must return 1 on a > b and 0 otherwise. For a min heap 1 on a < b and 0 otherwise.
comp | the comparison function of the heap |
minSize | the minimum size of the heap |
a | Vheap pointer |
NULL | error |
int elektraVheapInsert | ( | Vheap * | vheap, |
void * | data | ||
) |
Inserts an element in the Vheap, by finding the right position.
Resizes the memory first if needed.
data | the element |
0 | on error |
1 | otherwise |
int elektraVheapIsEmpty | ( | const Vheap * | vheap | ) |
Checks if the heap is empty.
1 | on empty |
0 | on non empty |
-1 | on error |
void* elektraVheapRemove | ( | Vheap * | vheap | ) |
Removes and returns an element from the Vheap, by taking the first element which is ordered by VheapComp, after removal the remaining elements get ordered again.
Resizes the heap if needed.
the | element |
NULL | on error |