Changeset 4315 for trunk/psLib/src/collections/psHash.c
- Timestamp:
- Jun 17, 2005, 4:30:50 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/collections/psHash.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/collections/psHash.c
r4136 r4315 12 12 * @author GLG, MHPCC 13 13 * 14 * @version $Revision: 1.1 7$ $Name: not supported by cvs2svn $15 * @date $Date: 2005-06- 07 22:37:52$14 * @version $Revision: 1.18 $ $Name: not supported by cvs2svn $ 15 * @date $Date: 2005-06-18 02:30:49 $ 16 16 * 17 17 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 43 43 The linked list 44 44 *****************************************************************************/ 45 psList* psHashKeyList( psHash* table)45 psList* psHashKeyList(const psHash* hash) 46 46 { 47 47 psS32 i = 0; // Loop index variable … … 49 49 psHashBucket* ptr = NULL; // Used to step thru linked list. 50 50 51 if ( table== NULL) {51 if (hash == NULL) { 52 52 return NULL; 53 53 } … … 57 57 // Loop through every bucket in the hash table. If that bucket is not 58 58 // NULL, then add the bucket's key to the linked list. 59 for (i = 0; i < table->nbucket; i++) {60 if ( table->buckets[i] != NULL) {59 for (i = 0; i < hash->nbucket; i++) { 60 if (hash->buckets[i] != NULL) { 61 61 // Since a bucket contains a linked list of keys/data, we must 62 62 // step trough each key in that linked list: 63 63 64 ptr = table->buckets[i];64 ptr = hash->buckets[i]; 65 65 while (ptr != NULL) { 66 66 psListAdd(myLinkList, PS_LIST_HEAD, ptr->key); … … 135 135 The new hash table. 136 136 *****************************************************************************/ 137 psHash* psHashAlloc( psS32 nbucket) // initial number of buckets137 psHash* psHashAlloc(long nalloc) // initial number of buckets 138 138 { 139 139 psS32 i = 0; // loop index variable … … 145 145 146 146 // Allocate memory for the buckets. 147 table->buckets = psAlloc(n bucket* sizeof(psHashBucket* ));148 table->nbucket = n bucket;149 150 psTrace("utils.hash", 1, "Creating %d-element hash table\n", n bucket);147 table->buckets = psAlloc(nalloc * sizeof(psHashBucket* )); 148 table->nbucket = nalloc; 149 150 psTrace("utils.hash", 1, "Creating %d-element hash table\n", nalloc); 151 151 152 152 // Initialize all buckets to NULL. 153 for (i = 0; i < n bucket; i++)153 for (i = 0; i < nalloc; i++) 154 154 { 155 155 table->buckets[i] = NULL; … … 383 383 boolean value defining success or failure 384 384 *****************************************************************************/ 385 psBool psHashRemove(psHash* table,386 const char *key)385 bool psHashRemove(psHash* table, 386 const char *key) 387 387 { 388 388 psPtr data = NULL;
Note:
See TracChangeset
for help on using the changeset viewer.
