IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1295


Ignore:
Timestamp:
Jul 23, 2004, 5:31:22 PM (22 years ago)
Author:
evanalst
Message:

Function psHashRemove was changed to return boolean and removes the data
from the hash table.

Location:
trunk/psLib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sysUtils/psHash.c

    r1202 r1295  
    1010 *  @author George Gusciora, MHPCC
    1111 *   
    12  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-08 22:05:14 $
     12 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-24 03:31:06 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    357357    itemFree: a function pointer
    358358Return:
    359     NONE
     359    boolean value defining success or failure
    360360 *****************************************************************************/
    361361bool psHashAdd(psHash *table, const char *key, void *data)
     
    407407    itemFree: a function pointer
    408408Return:
    409     The data that was associated with that key.
    410  *****************************************************************************/
    411 void *psHashRemove(psHash *table, const char *key)
    412 {
     409    boolean value defining success or failure
     410 *****************************************************************************/
     411bool psHashRemove(psHash *table, const char *key)
     412{
     413    void *data = NULL;
     414    bool retVal = false;
     415
    413416    if (table == NULL) {
    414417        psAbort(__func__, "psHashRemove() called with NULL hash table.");
     
    418421    }
    419422
    420     return doHashWork(table, key, NULL, 1);
    421 }
     423    data = doHashWork(table, key, NULL, 1);
     424    if ( data != NULL) {
     425        psFree(data);
     426        retVal = true;
     427    } else {
     428        retVal = false;
     429    }
     430    return retVal;
     431}
  • trunk/psLib/test/sysUtils/tst_psHash03.c

    r1201 r1295  
    6868    int i               = 0;
    6969    int TotalKeys       = 0;
     70    bool retVal         = false;
    7071    ID *id = NULL;
    7172    char *myKeys[] = {"ENTRY00", "ENTRY01", "ENTRY02", "ENTRY03", NULL};
     
    101102    i = 0;
    102103    while (myKeys[i] != NULL) {
    103         id = psHashRemove(myHashTable, myKeys[i]);
    104104        // The psHashRemove() procedure removes the entry from the hash
    105         // table, but does not delete the data.  The following is necessary
    106         // to delete the data as well (which is returned from the call).
    107         psFree(id);
     105        // table and deletes the data.
     106        retVal = psHashRemove(myHashTable, myKeys[i]);
     107        if (!retVal) {
     108            fprintf(stderr,"%s: Hash table entry not removed.\n",__func__);
     109        }
    108110        id = psHashLookup(myHashTable, myKeys[i]);
    109111        if (id != NULL) {
     
    124126        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    125127    }
    126     psMemCheckCorruption(1);
     128    psMemCheckCorruption(true);
    127129
    128130    return (!testStatus);
    129131}
     132
Note: See TracChangeset for help on using the changeset viewer.