IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 3, 2005, 10:28:07 AM (22 years ago)
Author:
desonia
Message:

added psHashToArray function and cooresponding test.

File:
1 edited

Legend:

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

    r2625 r2859  
    1010*  @author Robert Lupton, Princeton University
    1111*  @author George Gusciora, MHPCC
     12*  @author Robert DeSonia, MHPCC
    1213*
    13 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    14 *  @date $Date: 2004-12-04 02:43:39 $
     14*  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     15*  @date $Date: 2005-01-03 20:28:07 $
    1516*
    1617*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    361362    }
    362363
    363     return (doHashWork(table, key, data, 0) != NULL);
     364    return (doHashWork(table, key, data, false) != NULL);
    364365}
    365366
     
    389390    }
    390391
    391     return doHashWork(table, key, NULL, 0);
     392    return doHashWork(table, key, NULL, false);
    392393}
    393394
     
    418419    }
    419420
    420     data = doHashWork(table, key, NULL, 1);
     421    data = doHashWork(table, key, NULL, true);
    421422    if (data != NULL) {
    422423        retVal = true;
     
    427428    return retVal;
    428429}
     430
     431psArray* psHashToArray(psHash* table)
     432{
     433
     434    if (table == NULL) {
     435        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     436                PS_ERRORTEXT_psHash_TABLE_NULL);
     437        return NULL;
     438    }
     439
     440    // first, let's just count the number of data elements to know what size
     441    // psArray we need to allocate.
     442    int nElements = 0;
     443    int nbucket = table->nbucket;
     444    for (int i = 0; i < nbucket; i++) {
     445        psHashBucket* tmpBucket = table->buckets[i];
     446        while (tmpBucket != NULL) {
     447            nElements++;
     448            tmpBucket = tmpBucket->next;
     449        }
     450    }
     451
     452    psArray* result = psArrayAlloc(nElements);
     453    result->n = nElements;
     454
     455    // now fill in the array with the hash table's data
     456    psPtr* data = result->data;
     457    for (int i = 0; i < nbucket; i++) {
     458        psHashBucket* tmpBucket = table->buckets[i];
     459        while (tmpBucket != NULL) {
     460            *(data++) = psMemIncrRefCounter(tmpBucket->data);
     461            tmpBucket = tmpBucket->next;
     462        }
     463    }
     464
     465    return result;
     466}
Note: See TracChangeset for help on using the changeset viewer.