Changeset 9083
- Timestamp:
- Sep 30, 2006, 2:45:34 PM (20 years ago)
- Location:
- trunk/psLib/src/types
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/types/psHash.c
r8973 r9083 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.3 2$ $Name: not supported by cvs2svn $15 * @date $Date: 2006- 09-26 02:55:34 $14 * @version $Revision: 1.33 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2006-10-01 00:45:34 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 47 47 psList* psHashKeyList(const psHash* hash) 48 48 { 49 PS_ASSERT_PTR_NON_NULL(hash, NULL); 49 50 psS32 i = 0; // Loop index variable 50 51 psList* myLinkList = NULL; // The output data structure 51 52 psHashBucket* ptr = NULL; // Used to step thru linked list. 52 53 53 if (hash == NULL) {54 return NULL;55 }56 54 // Create the linked list 57 55 myLinkList = psListAlloc(NULL); … … 98 96 bucket->key = psStringCopy(key); 99 97 100 if (data == NULL) { 101 // NOTE: Should we flag a warning message? 102 bucket->data = NULL; 103 } else { 104 bucket->data = psMemIncrRefCounter(data); 105 } 98 //XXX: Since this function is static and only called by doHashWork, 99 //data can never be NULL here. 100 // if (data == NULL) { 101 // NOTE: Should we flag a warning message? 102 // bucket->data = NULL; 103 // } else { 104 bucket->data = psMemIncrRefCounter(data); 105 // } 106 106 107 107 bucket->next = next; … … 120 120 static void hashBucketFree(psHashBucket* bucket) 121 121 { 122 if (bucket == NULL) {123 return;124 }125 126 122 psFree(bucket->key); 127 128 123 psFree(bucket->data); 129 124 } … … 139 134 psHash* psHashAlloc(long nalloc) // initial number of buckets 140 135 { 136 if (nalloc < 0) 137 { 138 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 139 "Can't allocate a psHash of negative size."); 140 return NULL; 141 } 141 142 psS32 i = 0; // loop index variable 142 143 … … 185 186 psS32 i = 0; // Loop index variable. 186 187 187 if (table == NULL) {188 return;189 }190 188 // Loop through each bucket in the hash table. If that bucket is not 191 189 // NULL, then free the bucket via a function call to hashBucketFree(); … … 225 223 static psPtr doHashWork(psHash* table, 226 224 const char *key, 227 psPtr data, psBool remove 225 psPtr data, 226 psBool remove 228 227 ) 229 228 { … … 240 239 // function, but I'm checking it anyway since future coders might change 241 240 // the way this procedure is called. 242 if ((table == NULL) || (key == NULL)) {241 /* if ((table == NULL) || (key == NULL)) { 243 242 psError(PS_ERR_BAD_PARAMETER_NULL, true, 244 _("Input key can not be NULL."));243 _("Input key can not be NULL.")); 245 244 return NULL; 246 245 } 246 */ 247 247 // NOTE: This is the originally supplied hash function. 248 248 // for (psS32 i = 0, len = strlen(key); i < len; i++) { … … 253 253 // This hash algorithm is from Sedgewick. NOTE: must reread to ensure that 254 254 // the size of the hash table is not required to be a prime number. 255 if (table->n <= 0) 256 return NULL; 255 257 tmpchar = (char *)key; 256 258 for (hash = 0; *tmpchar != '\0'; tmpchar++) { … … 260 262 // NOTE: This should not be necessary, but for now, I'm checking bounds 261 263 // anyway. 262 if ((hash < 0) || (hash >= table->n)) {264 /* if ((hash < 0) || (hash >= table->n)) { 263 265 psError(PS_ERR_UNKNOWN, true, 264 "Internal hash function out of range (%" PRId64 ")", hash); 265 } 266 "Internal hash function out of range (%" PRId64 ")", hash); 267 } 268 */ 266 269 // ptr will have the correct hash bucket. 267 270 ptr = table->buckets[hash]; … … 397 400 const char *key) 398 401 { 402 PS_ASSERT_PTR_NON_NULL(hash, false); 403 PS_ASSERT_PTR_NON_NULL(key, false); 404 399 405 psPtr data = NULL; 400 406 psBool retVal = false; 401 402 PS_ASSERT_PTR_NON_NULL(hash, false);403 PS_ASSERT_PTR_NON_NULL(key, false);404 407 405 408 data = doHashWork(hash, key, NULL, true); … … 421 424 int nElements = 0; 422 425 int nbucket = hash->n; 426 //XXX: If we do psArrayAlloc(0) here and use psArrayAdd(result, 1, tmpBucket->data) 427 //we can eliminate the 2nd for loop below. 423 428 for (int i = 0; i < nbucket; i++) { 424 429 psHashBucket* tmpBucket = hash->buckets[i]; -
trunk/psLib/src/types/psHash.h
r8973 r9083 11 11 * @author GLG, MHPCC 12 12 * 13 * @version $Revision: 1.1 8$ $Name: not supported by cvs2svn $14 * @date $Date: 2006- 09-26 02:55:34 $13 * @version $Revision: 1.19 $ $Name: not supported by cvs2svn $ 14 * @date $Date: 2006-10-01 00:45:34 $ 15 15 * 16 16 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
Note:
See TracChangeset
for help on using the changeset viewer.
