Elektra  0.8.18
Functions

The Vheap structure. More...

Collaboration diagram for Vheap:

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...
 

Detailed Description

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.

Function Documentation

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.

Return values
1on success
0on 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.

Parameters
compthe comparison function of the heap
minSizethe minimum size of the heap
Return values
aVheap pointer
NULLerror
int elektraVheapInsert ( Vheap *  vheap,
void *  data 
)

Inserts an element in the Vheap, by finding the right position.

Resizes the memory first if needed.

Parameters
datathe element
Return values
0on error
1otherwise
int elektraVheapIsEmpty ( const Vheap *  vheap)

Checks if the heap is empty.

Return values
1on empty
0on non empty
-1on 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.

Return values
theelement
NULLon error