hash.c: K&R conversion to ANSI and constify arguments / callback

cb_heap_kill_t callback typedef created

Invoked from HeapKill()

No active callback implementation in the codebase.

callback interface (from hash.h):
  marked @invoke call-site
This commit is contained in:
Darryl L. Miles 2025-01-06 16:15:58 +00:00
parent d9cfd64d60
commit ff9487de1f
7 changed files with 73 additions and 72 deletions

View File

@ -139,7 +139,7 @@ GlGlobalRoute(chanList, netList)
glPenClearPerChan(net); glPenClearPerChan(net);
RtrMilestonePrint(); RtrMilestonePrint();
} }
HeapKill(&netHeap, (void (*)()) NULL); HeapKill(&netHeap, (cb_heap_kill_t) NULL);
glClientFree(chanList, netList); glClientFree(chanList, netList);
glChanFreeMap(); glChanFreeMap();
@ -333,7 +333,7 @@ glProcessLoc(startList, loc, bestCost, doFast)
headFree = glPathCurPage->glp_free; headFree = glPathCurPage->glp_free;
bestPt = glMazeFindPath(loc, bestCost); bestPt = glMazeFindPath(loc, bestCost);
glMazeResetCost(headPage, headFree); glMazeResetCost(headPage, headFree);
HeapKill(&glMazeHeap, (void (*)()) NULL); HeapKill(&glMazeHeap, (cb_heap_kill_t) NULL);
if (bestPt == (GlPoint *) NULL) if (bestPt == (GlPoint *) NULL)
{ {
glBadRoutes++; glBadRoutes++;
@ -372,7 +372,7 @@ glProcessLoc(startList, loc, bestCost, doFast)
} }
if (doFast) if (doFast)
glMazeResetCost(headPage, headFree); glMazeResetCost(headPage, headFree);
HeapKill(&glMazeHeap, (void (*)()) NULL); HeapKill(&glMazeHeap, (cb_heap_kill_t) NULL);
if (bestPt) if (bestPt)
{ {
if (glLogFile) if (glLogFile)

View File

@ -241,8 +241,8 @@ glRouteToPoint(loc, bestCost)
glHistoAdd(heapPts, frontierPts, startPts); glHistoAdd(heapPts, frontierPts, startPts);
/* Free the auxiliary heaps */ /* Free the auxiliary heaps */
HeapKill(&glBestHeap, (void (*)()) NULL); HeapKill(&glBestHeap, (cb_heap_kill_t) NULL);
HeapKill(&glProximityHeap, (void (*)()) NULL); HeapKill(&glProximityHeap, (cb_heap_kill_t) NULL);
return (lastPt); return (lastPt);
} }

View File

@ -476,7 +476,7 @@ glHistoDump()
} }
count++, total++; count++, total++;
} }
HeapKill(&histoHeap, (void (*)()) NULL); HeapKill(&histoHeap, (cb_heap_kill_t) NULL);
if (count > 0) if (count > 0)
fprintf(fp, "%d: %d\n", lastsize, count); fprintf(fp, "%d: %d\n", lastsize, count);
fprintf(fp, "TOTAL: %d\n", total); fprintf(fp, "TOTAL: %d\n", total);
@ -499,7 +499,7 @@ glHistoDump()
} }
count++, total++; count++, total++;
} }
HeapKill(&histoHeap, (void (*)()) NULL); HeapKill(&histoHeap, (cb_heap_kill_t) NULL);
if (count > 0) if (count > 0)
fprintf(fp, "%d: %d\n", lastsize, count); fprintf(fp, "%d: %d\n", lastsize, count);
fprintf(fp, "TOTAL: %d\n", total); fprintf(fp, "TOTAL: %d\n", total);

View File

@ -1550,7 +1550,7 @@ mzAssignVertexCosts()
} }
/* Free heap */ /* Free heap */
HeapKill(&adjHeap, (void (*)()) NULL); HeapKill(&adjHeap, (cb_heap_kill_t) NULL);
return; return;
} }

View File

@ -1292,10 +1292,10 @@ MZClean()
/* Free up route-path queues */ /* Free up route-path queues */
if(mzPathsDirty) if(mzPathsDirty)
{ {
HeapKill(&mzMaxToGoHeap, (void (*)()) NULL); HeapKill(&mzMaxToGoHeap, (cb_heap_kill_t) NULL);
HeapKill(&mzMinCostHeap, (void (*)()) NULL); HeapKill(&mzMinCostHeap, (cb_heap_kill_t) NULL);
HeapKill(&mzMinAdjCostHeap, (void (*)()) NULL); HeapKill(&mzMinAdjCostHeap, (cb_heap_kill_t) NULL);
HeapKill(&mzMinCostCompleteHeap, (void (*)()) NULL); HeapKill(&mzMinCostCompleteHeap, (cb_heap_kill_t) NULL);
ListDealloc(mzBloomStack); ListDealloc(mzBloomStack);
ListDealloc(mzStraightStack); ListDealloc(mzStraightStack);
ListDealloc(mzDownHillStack); ListDealloc(mzDownHillStack);

View File

@ -111,22 +111,22 @@ extern void heapify();
*/ */
void void
HeapInit(heap, size, descending, stringIds) HeapInit(
Heap *heap; /* Pointer to a heap struct */ Heap *heap, /* Pointer to a heap struct */
int size; /* Initial size of heap */ int size, /* Initial size of heap */
int descending; /* TRUE if largest on top */ int descending, /* TRUE if largest on top */
int stringIds; /* TRUE if entry id's are strings */ int stringIds) /* TRUE if entry id's are strings */
{ {
HeapInitType(heap, size, descending, stringIds, HE_INT); HeapInitType(heap, size, descending, stringIds, HE_INT);
} }
void void
HeapInitType(heap, size, descending, stringIds, keyType) HeapInitType(
Heap *heap; /* Pointer to a heap struct */ Heap *heap, /* Pointer to a heap struct */
int size; /* Initial size of heap */ int size, /* Initial size of heap */
int descending; /* TRUE if largest on top */ int descending, /* TRUE if largest on top */
int stringIds; /* TRUE if entry id's are strings */ int stringIds, /* TRUE if entry id's are strings */
int keyType; /* Type of keys to use */ int keyType) /* Type of keys to use */
{ {
if (size < 0) size = -size; if (size < 0) size = -size;
heap->he_size = 2; heap->he_size = 2;
@ -177,9 +177,9 @@ HeapInitType(heap, size, descending, stringIds, keyType)
*/ */
void void
HeapKill(heap, func) HeapKill(
Heap *heap; /* The heap being killed */ Heap *heap, /* The heap being killed */
void (*func)(); /* Some function to free each id element */ cb_heap_kill_t func) /* Some function to free each id element */
{ {
int i; int i;
@ -189,7 +189,7 @@ HeapKill(heap, func)
*/ */
if (func) if (func)
for (i = 1; i <= heap->he_used; i++) for (i = 1; i <= heap->he_used; i++)
(*func) (heap, i); (*func) (heap, i); /** @invoke cb_heap_kill_t */
freeMagic((char *) heap->he_list); freeMagic((char *) heap->he_list);
heap->he_list = NULL; heap->he_list = NULL;
} }
@ -212,9 +212,9 @@ HeapKill(heap, func)
*/ */
void void
HeapFreeIdFunc(heap, i) HeapFreeIdFunc(
Heap *heap; /* The heap in which the free is performed */ Heap *heap, /* The heap in which the free is performed */
int i; /* The index of the entry whose id gets freed */ int i) /* The index of the entry whose id gets freed */
{ {
if (heap->he_stringId) if (heap->he_stringId)
freeMagic(heap->he_list[i].he_id); freeMagic(heap->he_list[i].he_id);
@ -239,9 +239,9 @@ HeapFreeIdFunc(heap, i)
*/ */
HeapEntry * HeapEntry *
HeapRemoveTop(heap, entry) HeapRemoveTop(
Heap *heap; /* The heap from which the top is removed */ Heap *heap, /* The heap from which the top is removed */
HeapEntry *entry; /* Return the value in this struct */ HeapEntry *entry) /* Return the value in this struct */
{ {
int i; int i;
@ -278,8 +278,8 @@ HeapRemoveTop(heap, entry)
*/ */
HeapEntry * HeapEntry *
HeapLookAtTop(heap) HeapLookAtTop(
Heap *heap; Heap *heap)
{ {
int i; int i;
@ -311,9 +311,9 @@ HeapLookAtTop(heap)
*/ */
void void
heapify(heap, root) heapify(
Heap *heap; Heap *heap,
int root; int root)
{ {
HeapEntry *list = heap->he_list; HeapEntry *list = heap->he_list;
int x, r, used = heap->he_used; int x, r, used = heap->he_used;
@ -383,10 +383,10 @@ heapify(heap, root)
*/ */
void void
HeapAdd(heap, pKey, id) HeapAdd(
Heap *heap; Heap *heap,
union heUnion *pKey; union heUnion *pKey,
char *id; char *id)
{ {
HeapEntry *list = heap->he_list; HeapEntry *list = heap->he_list;
int i, cmp, keyType; int i, cmp, keyType;
@ -462,10 +462,10 @@ HeapAdd(heap, pKey, id)
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
*/ */
void void
HeapAddInt(heap, data, id) HeapAddInt(
Heap *heap; Heap *heap,
int data; int data,
char *id; char *id)
{ {
union heUnion pKey; union heUnion pKey;
@ -476,10 +476,10 @@ HeapAddInt(heap, data, id)
} }
void void
HeapAddDLong(heap, data, id) HeapAddDLong(
Heap *heap; Heap *heap,
dlong data; dlong data,
char *id; char *id)
{ {
union heUnion pKey; union heUnion pKey;
@ -490,10 +490,10 @@ HeapAddDLong(heap, data, id)
} }
void void
HeapAddFloat(heap, data, id) HeapAddFloat(
Heap *heap; Heap *heap,
float data; float data,
char *id; char *id)
{ {
union heUnion pKey; union heUnion pKey;
@ -504,10 +504,10 @@ HeapAddFloat(heap, data, id)
} }
void void
HeapAddDouble(heap, data, id) HeapAddDouble(
Heap *heap; Heap *heap,
double data; double data,
char *id; char *id)
{ {
union heUnion pKey; union heUnion pKey;
@ -534,8 +534,8 @@ HeapAddDouble(heap, data, id)
*/ */
void void
HeapDump(heap) HeapDump(
Heap *heap; Heap *heap)
{ {
int i; int i;

View File

@ -125,18 +125,19 @@ typedef struct
} Heap; } Heap;
/* PROCEDURES */ /* PROCEDURES */
extern void HeapInit(Heap *, int, int, int); extern void HeapInit(Heap *heap, int size, int descending, int stringIds);
extern void HeapInitType(Heap *, int, int, int, int); extern void HeapInitType(Heap *heap, int size, int descending, int stringIds, int keyType);
extern void HeapKill(Heap *, void (*)()); typedef void (*cb_heap_kill_t)(Heap *heap, int index);
extern void HeapFreeIdFunc(Heap *, int); extern void HeapKill(Heap *heap, cb_heap_kill_t func);
extern HeapEntry *HeapRemoveTop(Heap *, HeapEntry *); extern void HeapFreeIdFunc(Heap *heap, int i);
extern HeapEntry *HeapLookAtTop(Heap *); extern HeapEntry *HeapRemoveTop(Heap *heap, HeapEntry *entry);
extern void HeapAdd(Heap *, union heUnion *, char *); extern HeapEntry *HeapLookAtTop(Heap *heap);
extern void HeapAddInt(Heap *, int, char *); extern void HeapAdd(Heap *heap, union heUnion *pKey, char *id);
extern void HeapAddDLong(Heap *, dlong, char *); extern void HeapAddInt(Heap *heap, int data, char *id);
extern void HeapAddFloat(Heap *, float, char *); extern void HeapAddDLong(Heap *heap, dlong data, char *id);
extern void HeapAddDouble(Heap *, double, char *); extern void HeapAddFloat(Heap *heap, float data, char *id);
extern void HeapDump(Heap *); extern void HeapAddDouble(Heap *heap, double data, char *id);
extern void HeapDump(Heap *heap);
#define HEAP_EMPTY(h) ((h)->he_used == 0) #define HEAP_EMPTY(h) ((h)->he_used == 0)