comparison PrivateHash.c @ 4:1ee100564408

Changed malloc and free to VMS__malloc and VMS__free
author Me
date Sun, 31 Oct 2010 20:25:30 -0700
parents e6fe47763ee6
children e072db5aa783
comparison
equal deleted inserted replaced
2:52ee7ff0f3f2 3:40d29777ed73
16 16
17 17
18 HashTable * 18 HashTable *
19 makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn ) 19 makeHashTable( int numHashSlots, FreeEntryContentFnPtr freeFn )
20 { HashTable * retTable; 20 { HashTable * retTable;
21 retTable = malloc( sizeof( HashTable ) ); 21 retTable = VMS__malloc( sizeof( HashTable ) );
22 22
23 retTable->freeEntryContentFn = freeFn; 23 retTable->freeEntryContentFn = freeFn;
24 24
25 retTable->entries = malloc( numHashSlots * sizeof(HashEntry *) ); 25 retTable->entries = VMS__malloc( numHashSlots * sizeof(HashEntry *) );
26 retTable->numEntries = 0; 26 retTable->numEntries = 0;
27 retTable->tableSz = numHashSlots; 27 retTable->tableSz = numHashSlots;
28 28
29 nullOutTablesArray( retTable ); 29 nullOutTablesArray( retTable );
30 30
38 38
39 oldTableSz = table->tableSz; 39 oldTableSz = table->tableSz;
40 oldEntries = table->entries; 40 oldEntries = table->entries;
41 41
42 newTableSz = 2 * oldTableSz + 1; 42 newTableSz = 2 * oldTableSz + 1;
43 newEntries = malloc( newTableSz * sizeof(HashEntry *) ); 43 newEntries = VMS__malloc( newTableSz * sizeof(HashEntry *) );
44 44
45 table->tableSz = newTableSz; 45 table->tableSz = newTableSz;
46 table->entries = newEntries; 46 table->entries = newEntries;
47 table->numEntries = 0; //about to add them all back! 47 table->numEntries = 0; //about to add them all back!
48 48
110 HashEntry* hashEntry; 110 HashEntry* hashEntry;
111 111
112 hashEntry = getEntryFromTable( key, table ); 112 hashEntry = getEntryFromTable( key, table );
113 if( hashEntry == NULL ) 113 if( hashEntry == NULL )
114 { hashIdx = hashThisKey( key, table->tableSz ); 114 { hashIdx = hashThisKey( key, table->tableSz );
115 hashEntry = (HashEntry*) malloc( sizeof( HashEntry ) ); 115 hashEntry = (HashEntry*) VMS__malloc( sizeof( HashEntry ) );
116 if( hashEntry == NULL ) return 0; 116 if( hashEntry == NULL ) return 0;
117 hashEntry->key = strdup( key ); //TODO: figure out soln for incr Sz 117 hashEntry->key = strdup( key ); //TODO: figure out soln for incr Sz
118 if( hashEntry->key == NULL ) return 0; 118 if( hashEntry->key == NULL ) return 0;
119 hashEntry->next = (table->entries)[hashIdx]; 119 hashEntry->next = (table->entries)[hashIdx];
120 (table->entries)[hashIdx] = hashEntry; 120 (table->entries)[hashIdx] = hashEntry;
230 void 230 void
231 freeHashEntryUsing( HashEntry *entry, HashTable *table ) 231 freeHashEntryUsing( HashEntry *entry, HashTable *table )
232 { 232 {
233 if( entry->content != NULL ) 233 if( entry->content != NULL )
234 (*(table->freeEntryContentFn))( entry->content ); 234 (*(table->freeEntryContentFn))( entry->content );
235 free( entry->key ); //was malloc'd above, so free it 235 VMS__free( entry->key ); //was VMS__malloc'd above, so free it
236 free( entry ); 236 VMS__free( entry );
237 } 237 }
238 238
239 void 239 void
240 freeHashEntryButNotContent( HashEntry *entry ) 240 freeHashEntryButNotContent( HashEntry *entry )
241 { 241 {
242 free( entry->key ); //was malloc'd above, so free it 242 VMS__free( entry->key ); //was VMS__malloc'd above, so free it
243 free( entry ); 243 VMS__free( entry );
244 } 244 }
245 245