IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2859


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

added psHashToArray function and cooresponding test.

Location:
trunk/psLib
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/psLib.kdevses

    r2855 r2859  
    22<!DOCTYPE KDevPrjSession>
    33<KDevPrjSession>
    4  <DocsAndViews NumberOfDocuments="3" >
    5   <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/astronomy/psAstrometry.c" >
    6    <View0 Type="Source" />
     4 <DocsAndViews NumberOfDocuments="5" >
     5  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psHash.c" >
     6   <View0 line="451" Type="Source" />
    77  </Doc0>
    8   <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/test/astronomy/tst_psAstrometry.c" >
    9    <View0 Type="Source" />
     8  <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psHash.h" >
     9   <View0 line="42" Type="Source" />
    1010  </Doc1>
    1111  <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psArray.c" >
    12    <View0 line="91" Type="Source" />
     12   <View0 line="0" Type="Source" />
    1313  </Doc2>
     14  <Doc3 NumberOfViews="1" URL="file:/home/desonia/psLib/test/collections/tst_psHash04.c" >
     15   <View0 line="0" Type="Source" />
     16  </Doc3>
     17  <Doc4 NumberOfViews="1" URL="file:/home/desonia/psLib/test/collections/tst_psHash05.c" >
     18   <View0 line="31" Type="Source" />
     19  </Doc4>
    1420 </DocsAndViews>
    1521 <pluginList>
  • 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}
  • trunk/psLib/src/collections/psHash.h

    r2204 r2859  
    1010 *  @author Robert Lupton, Princeton University
    1111 *  @author George Gusciora, MHPCC
    12  *   
    13  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-27 00:57:31 $
     12 *  @author Robert DeSonia, MHPCC
     13 *
     14 *  @version $Revision: 1.6 $ $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
     
    2829typedef struct psHashBucket
    2930{
    30     char *key;                  ///< key for this item of data
    31     psPtr data;                 ///< the data itself
    32     struct psHashBucket* next;  ///< list of other possible keys
     31    char *key;                         ///< key for this item of data
     32    psPtr data;                        ///< the data itself
     33    struct psHashBucket* next;         ///< list of other possible keys
    3334}
    3435psHashBucket;
     
    3940typedef struct psHash
    4041{
    41     psS32 nbucket;                ///< Number of buckets in hash table.
    42     psHashBucket* *buckets;     ///< The bucket data.
     42    psS32 nbucket;                     ///< Number of buckets in hash table.
     43    psHashBucket* *buckets;            ///< The bucket data.
    4344}
    4445psHash;
    4546
    4647/// Allocate hash buckets in table.
    47 psHash* psHashAlloc(psS32 nbucket ///< The number of buckets to allocate.
    48                    );
     48psHash* psHashAlloc(
     49    psS32 nbucket                  ///< The number of buckets to allocate.
     50);
    4951
    5052/// Insert entry into table.
    51 psBool psHashAdd(psHash* table,  ///< table to insert in
    52                  const char *key, ///< key to use
    53                  psPtr data       ///< data to insert
    54                 );
     53psBool psHashAdd(
     54    psHash* table,                 ///< table to insert in
     55    const char *key,               ///< key to use
     56    psPtr data                     ///< data to insert
     57);
    5558
    5659/// Lookup key in table.
    57 psPtr psHashLookup(psHash* table,      ///< table to lookup key in
    58                    const char *key      ///< key to lookup
    59                   );
     60psPtr psHashLookup(
     61    psHash* table,                 ///< table to lookup key in
     62    const char *key                ///< key to lookup
     63);
    6064
    6165/// Remove key from table.
    62 psBool psHashRemove(psHash* table,       ///< table to lookup key in
    63                     const char *key       ///< key to lookup
    64                    );
     66psBool psHashRemove(
     67    psHash* table,                 ///< table to lookup key in
     68    const char *key                ///< key to lookup
     69);
    6570
    6671/// List all keys in table.
    67 psList* psHashKeyList(psHash* table    ///< table to list keys from.
    68                      );
     72psList* psHashKeyList(
     73    psHash* table                  ///< table to list keys from.
     74);
     75
     76/** Create a psArray from a psHash contents.
     77 *
     78 *  @return psArray*       A new psArray with duplicate contents of the input psHash
     79 */
     80psArray* psHashToArray(
     81    psHash* table                  ///< table to convert to psArray
     82);
    6983
    7084/* \} */// End of DataGroup Functions
  • trunk/psLib/src/types/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}
  • trunk/psLib/src/types/psHash.h

    r2204 r2859  
    1010 *  @author Robert Lupton, Princeton University
    1111 *  @author George Gusciora, MHPCC
    12  *   
    13  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-27 00:57:31 $
     12 *  @author Robert DeSonia, MHPCC
     13 *
     14 *  @version $Revision: 1.6 $ $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
     
    2829typedef struct psHashBucket
    2930{
    30     char *key;                  ///< key for this item of data
    31     psPtr data;                 ///< the data itself
    32     struct psHashBucket* next;  ///< list of other possible keys
     31    char *key;                         ///< key for this item of data
     32    psPtr data;                        ///< the data itself
     33    struct psHashBucket* next;         ///< list of other possible keys
    3334}
    3435psHashBucket;
     
    3940typedef struct psHash
    4041{
    41     psS32 nbucket;                ///< Number of buckets in hash table.
    42     psHashBucket* *buckets;     ///< The bucket data.
     42    psS32 nbucket;                     ///< Number of buckets in hash table.
     43    psHashBucket* *buckets;            ///< The bucket data.
    4344}
    4445psHash;
    4546
    4647/// Allocate hash buckets in table.
    47 psHash* psHashAlloc(psS32 nbucket ///< The number of buckets to allocate.
    48                    );
     48psHash* psHashAlloc(
     49    psS32 nbucket                  ///< The number of buckets to allocate.
     50);
    4951
    5052/// Insert entry into table.
    51 psBool psHashAdd(psHash* table,  ///< table to insert in
    52                  const char *key, ///< key to use
    53                  psPtr data       ///< data to insert
    54                 );
     53psBool psHashAdd(
     54    psHash* table,                 ///< table to insert in
     55    const char *key,               ///< key to use
     56    psPtr data                     ///< data to insert
     57);
    5558
    5659/// Lookup key in table.
    57 psPtr psHashLookup(psHash* table,      ///< table to lookup key in
    58                    const char *key      ///< key to lookup
    59                   );
     60psPtr psHashLookup(
     61    psHash* table,                 ///< table to lookup key in
     62    const char *key                ///< key to lookup
     63);
    6064
    6165/// Remove key from table.
    62 psBool psHashRemove(psHash* table,       ///< table to lookup key in
    63                     const char *key       ///< key to lookup
    64                    );
     66psBool psHashRemove(
     67    psHash* table,                 ///< table to lookup key in
     68    const char *key                ///< key to lookup
     69);
    6570
    6671/// List all keys in table.
    67 psList* psHashKeyList(psHash* table    ///< table to list keys from.
    68                      );
     72psList* psHashKeyList(
     73    psHash* table                  ///< table to list keys from.
     74);
     75
     76/** Create a psArray from a psHash contents.
     77 *
     78 *  @return psArray*       A new psArray with duplicate contents of the input psHash
     79 */
     80psArray* psHashToArray(
     81    psHash* table                  ///< table to convert to psArray
     82);
    6983
    7084/* \} */// End of DataGroup Functions
  • trunk/psLib/test/collections/Makefile

    r2830 r2859  
    33##  Makefile:   test/collections
    44##
    5 ##  $Revision: 1.26 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-12-27 21:12:47 $
     5##  $Revision: 1.27 $  $Name: not supported by cvs2svn $
     6##  $Date: 2005-01-03 20:28:07 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3434         tst_psHash03          \
    3535         tst_psHash04          \
     36         tst_psHash05          \
    3637         tst_psScalar
    3738
Note: See TracChangeset for help on using the changeset viewer.