Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > Hash_impl
comparison PrivateHash.c @ 29:18ec64d06e35
Renamed VMS to PR, in new branch
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Mon, 03 Sep 2012 15:03:38 -0700 |
| parents | b032601956bb |
| children | 1d42a512f482 |
comparison
equal
deleted
inserted
replaced
| 14:8b7b11b6a1c8 | 17:12857f5ae1e2 |
|---|---|
| 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_int__malloc( sizeof( HashTable ) ); | 15 retTable = PR_int__malloc( sizeof( HashTable ) ); |
| 16 | 16 |
| 17 retTable->freeEntryContentFn = freeFn; | 17 retTable->freeEntryContentFn = freeFn; |
| 18 | 18 |
| 19 retTable->entries = VMS_int__malloc( numHashSlots * sizeof(HashEntry *) ); | 19 retTable->entries = PR_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 |
| 26 } | 26 } |
| 27 | 27 |
| 28 HashTable * | 28 HashTable * |
| 29 makeHashTable_WL( int numHashSlots, FreeEntryContentFnPtr freeFn ) | 29 makeHashTable_WL( int numHashSlots, FreeEntryContentFnPtr freeFn ) |
| 30 { HashTable * retTable; | 30 { HashTable * retTable; |
| 31 retTable = VMS_WL__malloc( sizeof( HashTable ) ); | 31 retTable = PR_WL__malloc( sizeof( HashTable ) ); |
| 32 | 32 |
| 33 retTable->freeEntryContentFn = freeFn; | 33 retTable->freeEntryContentFn = freeFn; |
| 34 | 34 |
| 35 retTable->entries = VMS_int__malloc( numHashSlots * sizeof(HashEntry *) ); | 35 retTable->entries = PR_int__malloc( numHashSlots * sizeof(HashEntry *) ); |
| 36 retTable->numEntries = 0; | 36 retTable->numEntries = 0; |
| 37 retTable->tableSz = numHashSlots; | 37 retTable->tableSz = numHashSlots; |
| 38 | 38 |
| 39 nullOutTablesArray( retTable ); | 39 nullOutTablesArray( retTable ); |
| 40 | 40 |
| 48 | 48 |
| 49 oldTableSz = table->tableSz; | 49 oldTableSz = table->tableSz; |
| 50 oldEntries = table->entries; | 50 oldEntries = table->entries; |
| 51 | 51 |
| 52 newTableSz = 2 * oldTableSz; | 52 newTableSz = 2 * oldTableSz; |
| 53 newEntries = VMS_int__malloc( newTableSz * sizeof(HashEntry *) ); | 53 newEntries = PR_int__malloc( newTableSz * sizeof(HashEntry *) ); |
| 54 | 54 |
| 55 table->tableSz = newTableSz; | 55 table->tableSz = newTableSz; |
| 56 table->entries = newEntries; | 56 table->entries = newEntries; |
| 57 table->numEntries = 0; //about to add them all back! | 57 table->numEntries = 0; //about to add them all back! |
| 58 | 58 |
| 95 makeHashEntry( char * key ) | 95 makeHashEntry( char * key ) |
| 96 { HashEntry *hashEntry; | 96 { HashEntry *hashEntry; |
| 97 | 97 |
| 98 int32 len = strlen(key); | 98 int32 len = strlen(key); |
| 99 | 99 |
| 100 hashEntry = (HashEntry*) VMS_int__malloc( sizeof( HashEntry ) ); | 100 hashEntry = (HashEntry*) PR_int__malloc( sizeof( HashEntry ) ); |
| 101 if( hashEntry == NULL ) return NULL; | 101 if( hashEntry == NULL ) return NULL; |
| 102 | 102 |
| 103 hashEntry->key = VMS_int__malloc( len + 1 ); | 103 hashEntry->key = PR_int__malloc( len + 1 ); |
| 104 if( hashEntry->key == NULL ) return NULL; | 104 if( hashEntry->key == NULL ) return NULL; |
| 105 memcpy( hashEntry->key, key, len + 1 ); | 105 memcpy( hashEntry->key, key, len + 1 ); |
| 106 hashEntry->next = NULL; | 106 hashEntry->next = NULL; |
| 107 | 107 |
| 108 return hashEntry; | 108 return hashEntry; |
| 257 void | 257 void |
| 258 freeHashEntryUsing( HashEntry *entry, HashTable *table ) | 258 freeHashEntryUsing( HashEntry *entry, HashTable *table ) |
| 259 { | 259 { |
| 260 if( entry->content != NULL ) | 260 if( entry->content != NULL ) |
| 261 (*(table->freeEntryContentFn))( entry->content ); | 261 (*(table->freeEntryContentFn))( entry->content ); |
| 262 VMS_int__free( entry->key ); //was VMS_int__malloc'd above, so free it | 262 PR_int__free( entry->key ); //was PR_int__malloc'd above, so free it |
| 263 VMS_int__free( entry ); | 263 PR_int__free( entry ); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void | 266 void |
| 267 freeHashEntryUsing_WL( HashEntry *entry, HashTable *table ) | 267 freeHashEntryUsing_WL( HashEntry *entry, HashTable *table ) |
| 268 { | 268 { |
| 269 if( entry->content != NULL ) | 269 if( entry->content != NULL ) |
| 270 (*(table->freeEntryContentFn))( entry->content ); | 270 (*(table->freeEntryContentFn))( entry->content ); |
| 271 VMS_WL__free( entry->key ); //was VMS_int__malloc'd above, so free it | 271 PR_WL__free( entry->key ); //was PR_int__malloc'd above, so free it |
| 272 VMS_WL__free( entry ); | 272 PR_WL__free( entry ); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void | 275 void |
| 276 freeHashTable_WL( HashTable *table ) | 276 freeHashTable_WL( HashTable *table ) |
| 277 { int i; | 277 { int i; |
| 293 | 293 |
| 294 | 294 |
| 295 void | 295 void |
| 296 freeHashEntryButNotContent( HashEntry *entry ) | 296 freeHashEntryButNotContent( HashEntry *entry ) |
| 297 { | 297 { |
| 298 VMS_int__free( entry->key ); //was VMS_int__malloc'd above, so free it | 298 PR_int__free( entry->key ); //was PR_int__malloc'd above, so free it |
| 299 VMS_int__free( entry ); | 299 PR_int__free( entry ); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void | 302 void |
| 303 freeHashEntryButNotContent_WL( HashEntry *entry ) | 303 freeHashEntryButNotContent_WL( HashEntry *entry ) |
| 304 { | 304 { |
| 305 VMS_WL__free( entry->key ); //was VMS_int__malloc'd above, so free it | 305 PR_WL__free( entry->key ); //was PR_int__malloc'd above, so free it |
| 306 VMS_WL__free( entry ); | 306 PR_WL__free( entry ); |
| 307 } | 307 } |
| 308 | 308 |
| 309 | 309 |
| 310 | 310 |
| 311 | 311 |
| 320 HashTable * | 320 HashTable * |
| 321 makeHashTable32( int powerOf2OfSz, FreeEntryContentFnPtr freeFn ) | 321 makeHashTable32( int powerOf2OfSz, FreeEntryContentFnPtr freeFn ) |
| 322 { HashTable * retTable; | 322 { HashTable * retTable; |
| 323 int32 numHashSlots; | 323 int32 numHashSlots; |
| 324 | 324 |
| 325 retTable = VMS_int__malloc( sizeof( HashTable ) ); | 325 retTable = PR_int__malloc( sizeof( HashTable ) ); |
| 326 | 326 |
| 327 numHashSlots = 1 << powerOf2OfSz; | 327 numHashSlots = 1 << powerOf2OfSz; |
| 328 retTable->hashMask = 0xffffffff >> 32 - powerOf2OfSz; | 328 retTable->hashMask = 0xffffffff >> 32 - powerOf2OfSz; |
| 329 retTable->prevHash = (int32)rand(); | 329 retTable->prevHash = (int32)rand(); |
| 330 | 330 |
| 331 retTable->freeEntryContentFn = freeFn; | 331 retTable->freeEntryContentFn = freeFn; |
| 332 | 332 |
| 333 retTable->entries = VMS_int__malloc( numHashSlots * sizeof(HashEntry *)); | 333 retTable->entries = PR_int__malloc( numHashSlots * sizeof(HashEntry *)); |
| 334 retTable->numEntries = 0; | 334 retTable->numEntries = 0; |
| 335 retTable->tableSz = numHashSlots; | 335 retTable->tableSz = numHashSlots; |
| 336 | 336 |
| 337 nullOutTablesArray( retTable ); | 337 nullOutTablesArray( retTable ); |
| 338 | 338 |
| 347 | 347 |
| 348 HashEntry * | 348 HashEntry * |
| 349 makeHashEntry32( uint32 * key ) | 349 makeHashEntry32( uint32 * key ) |
| 350 { HashEntry *hashEntry; | 350 { HashEntry *hashEntry; |
| 351 | 351 |
| 352 hashEntry = (HashEntry*) VMS_int__malloc( sizeof( HashEntry ) ); | 352 hashEntry = (HashEntry*) PR_int__malloc( sizeof( HashEntry ) ); |
| 353 if( hashEntry == NULL ) return NULL; | 353 if( hashEntry == NULL ) return NULL; |
| 354 hashEntry->key = VMS_int__malloc( sizeOfKey(key) ); | 354 hashEntry->key = PR_int__malloc( sizeOfKey(key) ); |
| 355 if( hashEntry->key == NULL ) return NULL; | 355 if( hashEntry->key == NULL ) return NULL; |
| 356 memcpy( hashEntry->key, key, sizeOfKey(key) ); | 356 memcpy( hashEntry->key, key, sizeOfKey(key) ); |
| 357 hashEntry->next = NULL; | 357 hashEntry->next = NULL; |
| 358 | 358 |
| 359 return hashEntry; | 359 return hashEntry; |
| 395 | 395 |
| 396 oldTableSz = table->tableSz; | 396 oldTableSz = table->tableSz; |
| 397 oldEntries = table->entries; | 397 oldEntries = table->entries; |
| 398 | 398 |
| 399 newTableSz = 2 * oldTableSz; | 399 newTableSz = 2 * oldTableSz; |
| 400 newEntries = VMS_int__malloc( newTableSz * sizeof(HashEntry *) ); | 400 newEntries = PR_int__malloc( newTableSz * sizeof(HashEntry *) ); |
| 401 | 401 |
| 402 table->tableSz = newTableSz; | 402 table->tableSz = newTableSz; |
| 403 table->entries = newEntries; | 403 table->entries = newEntries; |
| 404 table->numEntries = 0; //about to add them all back! | 404 table->numEntries = 0; //about to add them all back! |
| 405 | 405 |
