Woolz Image Processing Version 1.4.0
AlcHeap

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

Files

file  AlcHeap.c
 

A basic heap data structure.


Functions

AlcHeapAlcHeapNew (int entSz, int entInc, void *data)
 Constructs a new heap data structure.
void AlcHeapFree (AlcHeap *heap)
 Frees the given heap data structure along with it's entries.
void AlcHeapEntFree (AlcHeap *heap)
 Frees the entry at the top of the heap.
void AlcHeapAllEntFree (AlcHeap *heap, int reallyFree)
 Frees all the heap entries.
AlcErrno AlcHeapInsertEnt (AlcHeap *heap, void *ent)
 Inserts the given entry into the queue.
void * AlcHeapTop (AlcHeap *heap)
 Gets the top heap entry.

Function Documentation

AlcHeap* AlcHeapNew ( int  entSz,
int  entInc,
void *  data 
)

Constructs a new heap data structure.

Returns:
New heap data structure, NULL on error.

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(), and WlzCMeshFMarNodes3D().

void AlcHeapFree ( AlcHeap heap)

Frees the given heap data structure along with it's entries.

Parameters:
heapThe heap to free.

References AlcFree(), and _AlcHeap::entries.

Referenced by WlzCMeshFMarNodes2D(), and WlzCMeshFMarNodes3D().

void AlcHeapEntFree ( AlcHeap heap)

Frees the entry at the top of the heap.

Parameters:
heapThe heap.

References _AlcHeap::entries, _AlcHeap::entSz, and _AlcHeap::nEnt.

Referenced by WlzCMeshFMarNodes2D(), and WlzCMeshFMarNodes3D().

void AlcHeapAllEntFree ( AlcHeap heap,
int  reallyFree 
)

Frees all the heap entries.

Parameters:
heapThe heap.
reallyFreeIf non zero the entries are really freed rather than just marked free and available for reuse.

References AlcFree(), _AlcHeap::entries, and _AlcHeap::nEnt.

Referenced by WlzCMeshFMarNodes2D(), and WlzCMeshFMarNodes3D().

AlcErrno AlcHeapInsertEnt ( AlcHeap heap,
void *  ent 
)

Inserts the given entry into the queue.

Returns:
Error code.
Parameters:
heapGiven heap data structure.
entEntry to insert.

References ALC_ER_ALLOC, ALC_ER_NONE, AlcRealloc(), _AlcHeap::entInc, _AlcHeap::entries, _AlcHeap::entSz, _AlcHeap::maxEnt, and _AlcHeap::nEnt.

void* AlcHeapTop ( AlcHeap heap)

Gets the top heap entry.

Returns:
The entry at the top of the heap.
Parameters:
heapGiven priority queue.

References _AlcHeap::entries, and _AlcHeap::nEnt.

Referenced by WlzCMeshFMarNodes2D(), and WlzCMeshFMarNodes3D().