Changeset 2859
- Timestamp:
- Jan 3, 2005, 10:28:07 AM (22 years ago)
- Location:
- trunk/psLib
- Files:
-
- 1 added
- 7 edited
-
psLib.kdevelop.pcs (modified) ( previous)
-
psLib.kdevses (modified) (1 diff)
-
src/collections/psHash.c (modified) (5 diffs)
-
src/collections/psHash.h (modified) (3 diffs)
-
src/types/psHash.c (modified) (5 diffs)
-
src/types/psHash.h (modified) (3 diffs)
-
test/collections/Makefile (modified) (2 diffs)
-
test/collections/tst_psHash05.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/psLib.kdevses
r2855 r2859 2 2 <!DOCTYPE KDevPrjSession> 3 3 <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" /> 7 7 </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" /> 10 10 </Doc1> 11 11 <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psArray.c" > 12 <View0 line=" 91" Type="Source" />12 <View0 line="0" Type="Source" /> 13 13 </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> 14 20 </DocsAndViews> 15 21 <pluginList> -
trunk/psLib/src/collections/psHash.c
r2625 r2859 10 10 * @author Robert Lupton, Princeton University 11 11 * @author George Gusciora, MHPCC 12 * @author Robert DeSonia, MHPCC 12 13 * 13 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $14 * @date $Date: 200 4-12-04 02:43:39$14 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-01-03 20:28:07 $ 15 16 * 16 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 361 362 } 362 363 363 return (doHashWork(table, key, data, 0) != NULL);364 return (doHashWork(table, key, data, false) != NULL); 364 365 } 365 366 … … 389 390 } 390 391 391 return doHashWork(table, key, NULL, 0);392 return doHashWork(table, key, NULL, false); 392 393 } 393 394 … … 418 419 } 419 420 420 data = doHashWork(table, key, NULL, 1);421 data = doHashWork(table, key, NULL, true); 421 422 if (data != NULL) { 422 423 retVal = true; … … 427 428 return retVal; 428 429 } 430 431 psArray* 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 10 10 * @author Robert Lupton, Princeton University 11 11 * @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 $ 15 16 * 16 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 29 typedef struct psHashBucket 29 30 { 30 char *key; ///< key for this item of data31 psPtr data; ///< the data itself32 struct psHashBucket* next; ///< list of other possible keys31 char *key; ///< key for this item of data 32 psPtr data; ///< the data itself 33 struct psHashBucket* next; ///< list of other possible keys 33 34 } 34 35 psHashBucket; … … 39 40 typedef struct psHash 40 41 { 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. 43 44 } 44 45 psHash; 45 46 46 47 /// Allocate hash buckets in table. 47 psHash* psHashAlloc(psS32 nbucket ///< The number of buckets to allocate. 48 ); 48 psHash* psHashAlloc( 49 psS32 nbucket ///< The number of buckets to allocate. 50 ); 49 51 50 52 /// 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 ); 53 psBool psHashAdd( 54 psHash* table, ///< table to insert in 55 const char *key, ///< key to use 56 psPtr data ///< data to insert 57 ); 55 58 56 59 /// Lookup key in table. 57 psPtr psHashLookup(psHash* table, ///< table to lookup key in 58 const char *key ///< key to lookup 59 ); 60 psPtr psHashLookup( 61 psHash* table, ///< table to lookup key in 62 const char *key ///< key to lookup 63 ); 60 64 61 65 /// Remove key from table. 62 psBool psHashRemove(psHash* table, ///< table to lookup key in 63 const char *key ///< key to lookup 64 ); 66 psBool psHashRemove( 67 psHash* table, ///< table to lookup key in 68 const char *key ///< key to lookup 69 ); 65 70 66 71 /// List all keys in table. 67 psList* psHashKeyList(psHash* table ///< table to list keys from. 68 ); 72 psList* 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 */ 80 psArray* psHashToArray( 81 psHash* table ///< table to convert to psArray 82 ); 69 83 70 84 /* \} */// End of DataGroup Functions -
trunk/psLib/src/types/psHash.c
r2625 r2859 10 10 * @author Robert Lupton, Princeton University 11 11 * @author George Gusciora, MHPCC 12 * @author Robert DeSonia, MHPCC 12 13 * 13 * @version $Revision: 1.1 0$ $Name: not supported by cvs2svn $14 * @date $Date: 200 4-12-04 02:43:39$14 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-01-03 20:28:07 $ 15 16 * 16 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 361 362 } 362 363 363 return (doHashWork(table, key, data, 0) != NULL);364 return (doHashWork(table, key, data, false) != NULL); 364 365 } 365 366 … … 389 390 } 390 391 391 return doHashWork(table, key, NULL, 0);392 return doHashWork(table, key, NULL, false); 392 393 } 393 394 … … 418 419 } 419 420 420 data = doHashWork(table, key, NULL, 1);421 data = doHashWork(table, key, NULL, true); 421 422 if (data != NULL) { 422 423 retVal = true; … … 427 428 return retVal; 428 429 } 430 431 psArray* 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 10 10 * @author Robert Lupton, Princeton University 11 11 * @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 $ 15 16 * 16 17 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 29 typedef struct psHashBucket 29 30 { 30 char *key; ///< key for this item of data31 psPtr data; ///< the data itself32 struct psHashBucket* next; ///< list of other possible keys31 char *key; ///< key for this item of data 32 psPtr data; ///< the data itself 33 struct psHashBucket* next; ///< list of other possible keys 33 34 } 34 35 psHashBucket; … … 39 40 typedef struct psHash 40 41 { 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. 43 44 } 44 45 psHash; 45 46 46 47 /// Allocate hash buckets in table. 47 psHash* psHashAlloc(psS32 nbucket ///< The number of buckets to allocate. 48 ); 48 psHash* psHashAlloc( 49 psS32 nbucket ///< The number of buckets to allocate. 50 ); 49 51 50 52 /// 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 ); 53 psBool psHashAdd( 54 psHash* table, ///< table to insert in 55 const char *key, ///< key to use 56 psPtr data ///< data to insert 57 ); 55 58 56 59 /// Lookup key in table. 57 psPtr psHashLookup(psHash* table, ///< table to lookup key in 58 const char *key ///< key to lookup 59 ); 60 psPtr psHashLookup( 61 psHash* table, ///< table to lookup key in 62 const char *key ///< key to lookup 63 ); 60 64 61 65 /// Remove key from table. 62 psBool psHashRemove(psHash* table, ///< table to lookup key in 63 const char *key ///< key to lookup 64 ); 66 psBool psHashRemove( 67 psHash* table, ///< table to lookup key in 68 const char *key ///< key to lookup 69 ); 65 70 66 71 /// List all keys in table. 67 psList* psHashKeyList(psHash* table ///< table to list keys from. 68 ); 72 psList* 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 */ 80 psArray* psHashToArray( 81 psHash* table ///< table to convert to psArray 82 ); 69 83 70 84 /* \} */// End of DataGroup Functions -
trunk/psLib/test/collections/Makefile
r2830 r2859 3 3 ## Makefile: test/collections 4 4 ## 5 ## $Revision: 1.2 6$ $Name: not supported by cvs2svn $6 ## $Date: 200 4-12-27 21:12:47 $5 ## $Revision: 1.27 $ $Name: not supported by cvs2svn $ 6 ## $Date: 2005-01-03 20:28:07 $ 7 7 ## 8 8 ## Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 34 34 tst_psHash03 \ 35 35 tst_psHash04 \ 36 tst_psHash05 \ 36 37 tst_psScalar 37 38
Note:
See TracChangeset
for help on using the changeset viewer.
