Woolz Image Processing
Version 1.8.3
|
Files | |
file | AlcHeap.c |
A basic heap data structure which uses an array. | |
Data Structures | |
struct | _AlcHeapEntryCore |
Core heap entry data structure. All other heap entry data structures must have the fields of this data structure first. Typedef: AlcHeapEntryCore. More... | |
struct | _AlcHeap |
A general purpose heap data structure. Typedef: AlcHeap. More... | |
Functions | |
AlcHeap * | AlcHeapNew (int entSz, int entInc, void *data) |
Constructs a new heap data structure. More... | |
void | AlcHeapFree (AlcHeap *heap) |
Frees the given heap data structure along with it's entries. More... | |
void | AlcHeapEntFree (AlcHeap *heap) |
Frees the entry at the top of the heap. More... | |
void | AlcHeapAllEntFree (AlcHeap *heap, int reallyFree) |
Frees all the heap entries. More... | |
AlcErrno | AlcHeapInsertEnt (AlcHeap *heap, void *ent) |
Inserts the given entry into the queue. More... | |
void * | AlcHeapTop (AlcHeap *heap) |
Gets the top heap entry. More... | |
AlcHeap* AlcHeapNew | ( | int | entSz, |
int | entInc, | ||
void * | data | ||
) |
Constructs a new heap data structure.
The following example code illustrates the use of the heap data structures and functions, although (for clarity and succinctness) without any error checking.
typedef struct _AlcHeapEntryTest { double priority; int index; } AlcHeapEntryTest; int main(int argc, char *argv[]) { int idN, size = 10; AlcHeap *heap = NULL; double *randoms = NULL; AlcHeapEntryTest ent; AlcHeapEntryTest *entP; AlcErrno alcErr = ALC_ER_NONE; randoms = (double *)AlcMalloc(sizeof(double) * size); srand(0); for(idN = 0; idN < size; ++idN) { randoms[idN] = (double)rand() / (double )(RAND_MAX); } heap = AlcHeapNew(sizeof(AlcHeapEntryTest), (size + 1) / 2, NULL); for(idN = 0; idN < size; ++idN) { ent.priority = randoms[idN]; ent.index = idN; AlcHeapInsertEnt(heap, &ent); } for(idN = 0; idN < size; ++idN) { entP = AlcHeapTop(heap); (void )printf("% 8d % 8d %1.12lf\n", idN, entP->index, entP->priority); AlcHeapEntFree(heap); } AlcHeapFree(heap); AlcFree(randoms); }
entSz Size of the heap entries. entInc Number of entries to allocate at once or zero for the default (1024). data Application specific data which is ignored by heap functions, may be NULL.
References AlcCalloc(), _AlcFreeStack::data, _AlcHeap::data, _AlcHeap::entInc, and _AlcHeap::entSz.
Referenced by WlzCMeshFMarNodes2D(), WlzCMeshFMarNodes3D(), WlzLineSkeleton(), and WlzThinToPoints().
void AlcHeapFree | ( | AlcHeap * | heap | ) |
Frees the given heap data structure along with it's entries.
heap | The heap to free. |
References AlcFree(), and _AlcHeap::entries.
void AlcHeapEntFree | ( | AlcHeap * | heap | ) |
void AlcHeapAllEntFree | ( | AlcHeap * | heap, |
int | reallyFree | ||
) |
Frees all the heap entries.
heap | The heap. |
reallyFree | If non zero the entries are really freed rather than just marked free and available for reuse. |
References AlcFree(), _AlcHeap::entries, and _AlcHeap::nEnt.
Inserts the given entry into the queue.
heap | Given heap data structure. |
ent | Entry to insert. |
References ALC_ER_ALLOC, ALC_ER_NONE, AlcRealloc(), _AlcHeap::entInc, _AlcHeap::entries, _AlcHeap::entSz, _AlcHeap::maxEnt, and _AlcHeap::nEnt.
Referenced by WlzLineSkeleton().
void* AlcHeapTop | ( | AlcHeap * | heap | ) |
Gets the top heap entry.
heap | Given heap. |
References _AlcHeap::entries, and _AlcHeap::nEnt.
Referenced by WlzLineSkeleton().