Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Hash_impl
comparison PrivateHash.c @ 17:774396bc53b4
updated for VMS name chgs from VMS__malloc to VMS_int__malloc
| author | Me@portablequad |
|---|---|
| date | Sun, 12 Feb 2012 01:46:00 -0800 |
| parents | 5b89d57e5d10 |
| children | 4b5abed39ab9 |
comparison
equal
deleted
inserted
replaced
| 9:1ab7e85a5b92 | 11:078a29c98873 |
|---|---|
| 10 | 10 |
| 11 | 11 |
| 12 HashTable * | 12 HashTable * |
| 13 makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) | 13 makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) |
| 14 { HashTable * retTable; | 14 { HashTable * retTable; |
| 15 retTable = VMS__malloc( sizeof( HashTable ) ); | 15 retTable = VMS_int__malloc( sizeof( HashTable ) ); |
| 16 | 16 |
| 17 retTable->freeEntryContentFn = freeFn; | 17 retTable->freeEntryContentFn = freeFn; |
| 18 | 18 |
| 19 retTable->entries = VMS__malloc( numHashSlots * sizeof(HashEntry *) ); | 19 retTable->entries = VMS_int__malloc( numHashSlots * sizeof(HashEntry *) ); |
| 20 retTable->numEntries = 0; | 20 retTable->numEntries = 0; |
| 21 retTable->tableSz = numHashSlots; | 21 retTable->tableSz = numHashSlots; |
| 22 | 22 |
| 23 nullOutTablesArray( retTable ); | 23 nullOutTablesArray( retTable ); |
| 24 | 24 |
| 32 | 32 |
| 33 oldTableSz = table->tableSz; | 33 oldTableSz = table->tableSz; |
| 34 oldEntries = table->entries; | 34 oldEntries = table->entries; |
| 35 | 35 |
| 36 newTableSz = 2 * oldTableSz + 1; | 36 newTableSz = 2 * oldTableSz + 1; |
| 37 newEntries = VMS__malloc( newTableSz * sizeof(HashEntry *) ); | 37 newEntries = VMS_int__malloc( newTableSz * sizeof(HashEntry *) ); |
| 38 | 38 |
| 39 table->tableSz = newTableSz; | 39 table->tableSz = newTableSz; |
| 40 table->entries = newEntries; | 40 table->entries = newEntries; |
| 41 table->numEntries = 0; //about to add them all back! | 41 table->numEntries = 0; //about to add them all back! |
| 42 | 42 |
| 108 HashEntry* hashEntry; | 108 HashEntry* hashEntry; |
| 109 | 109 |
| 110 hashEntry = getEntryFromTable( key, table ); | 110 hashEntry = getEntryFromTable( key, table ); |
| 111 if( hashEntry == NULL ) | 111 if( hashEntry == NULL ) |
| 112 { hashIdx = hashThisKey( key, table->tableSz ); | 112 { hashIdx = hashThisKey( key, table->tableSz ); |
| 113 hashEntry = (HashEntry*) VMS__malloc( sizeof( HashEntry ) ); | 113 hashEntry = (HashEntry*) VMS_int__malloc( sizeof( HashEntry ) ); |
| 114 if( hashEntry == NULL ) return 0; | 114 if( hashEntry == NULL ) return 0; |
| 115 hashEntry->key = VMS__malloc( sizeof(hashkey_t) ); | 115 hashEntry->key = VMS_int__malloc( sizeof(hashkey_t) ); |
| 116 if( hashEntry->key == NULL ) return 0; | 116 if( hashEntry->key == NULL ) return 0; |
| 117 memcpy( hashEntry->key, key, sizeof(hashkey_t) ); | 117 memcpy( hashEntry->key, key, sizeof(hashkey_t) ); |
| 118 hashEntry->next = (table->entries)[hashIdx]; | 118 hashEntry->next = (table->entries)[hashIdx]; |
| 119 (table->entries)[hashIdx] = hashEntry; | 119 (table->entries)[hashIdx] = hashEntry; |
| 120 table->numEntries += 1; | 120 table->numEntries += 1; |
| 227 void | 227 void |
| 228 freeHashEntryUsing( HashEntry *entry, HashTable *table ) | 228 freeHashEntryUsing( HashEntry *entry, HashTable *table ) |
| 229 { | 229 { |
| 230 if( entry->content != NULL ) | 230 if( entry->content != NULL ) |
| 231 (*(table->freeEntryContentFn))( entry->content ); | 231 (*(table->freeEntryContentFn))( entry->content ); |
| 232 VMS__free( entry->key ); //was VMS__malloc'd above, so free it | 232 VMS_int__free( entry->key ); //was VMS__malloc'd above, so free it |
| 233 VMS__free( entry ); | 233 VMS_int__free( entry ); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void | 236 void |
| 237 freeHashEntryButNotContent( HashEntry *entry ) | 237 freeHashEntryButNotContent( HashEntry *entry ) |
| 238 { | 238 { |
| 239 VMS__free( entry->key ); //was VMS__malloc'd above, so free it | 239 VMS_int__free( entry->key ); //was VMS__malloc'd above, so free it |
| 240 VMS__free( entry ); | 240 VMS_int__free( entry ); |
| 241 } | 241 } |
| 242 | 242 |
