rts/Hash.c
/* -----------------------------------------------------------------------------
 * When we free a hash table, we are also good enough to free the
 * data part of each (key, data) pair, as long as our caller can tell
 * us how to do it.
 * -------------------------------------------------------------------------- */
When we free a hash table, we are also good enough to free the
data part of each (key, data) pair, as long as our caller can tell
us how to do it.
When we free a hash table we are also good enough to free the data part of each ( key data ) pair as long as our caller can tell us how to do it .
void
freeHashTable(HashTable *table, void (*freeDataFun)(void *) )
{
    long segment;
    long index;
    HashList *hl;
    HashList *next;
    HashListChunk *cl, *cl_next;
    segment = (table->max + table->split - 1) / HSEGSIZE;
    index = (table->max + table->split - 1) % HSEGSIZE;
    while (segment >= 0) {
        while (index >= 0) {
            for (hl = table->dir[segment][index]; hl != NULL; hl = next) {
                next = hl->next;
                if (freeDataFun != NULL)
                    (*freeDataFun)(hl->data);
            }
            index--;
        }
        stgFree(table->dir[segment]);
        segment--;
        index = HSEGSIZE - 1;
    }
    for (cl = table->chunks; cl != NULL; cl = cl_next) {
        cl_next = cl->next;
        stgFree(cl->chunk);
        stgFree(cl);
    }
    stgFree(table);
}
void freeHashTable ( HashTable * table , void ( * freeDataFun ) ( void * ) ) { long segment ; long index ; HashList * hl ; HashList * next ; HashListChunk * cl , * cl_next ; segment = ( table -> max + table -> split - 1 ) / HSEGSIZE ; index = ( table -> max + table -> split - 1 ) % HSEGSIZE ; while ( segment >= 0 ) { while ( index >= 0 ) { for ( hl = table -> dir [ segment ] [ index ] ; hl != NULL ; hl = next ) { next = hl -> next ; if ( freeDataFun != NULL ) ( * freeDataFun ) ( hl -> data ) ; } index -- ; } stgFree ( table -> dir [ segment ] ) ; segment -- ; index = HSEGSIZE - 1 ; } for ( cl = table -> chunks ; cl != NULL ; cl = cl_next ) { cl_next = cl -> next ; stgFree ( cl -> chunk ) ; stgFree ( cl ) ; } stgFree ( table ) ; }
When we free a hash table, we are also good enough to free the
 data part of each (key, data) pair, as long as our caller can tell
 us how to do it.
When we free a hash table we are also good enough to free the data part of each ( key data ) pair as long as our caller can tell us how to do it .
/* The last bucket with something in it is table->max + table->split - 1 */