-------------------------------------------------------------------------*/ @brief Delete a key in a dictionary @param d dictionary object to modify. @param key Key to remove. @return void This function deletes a key in a dictionary. Nothing is done if the key cannot be found. */ --------------------------------------------------------------------------*/
| 448 | */ |
| 449 | /*--------------------------------------------------------------------------*/ |
| 450 | static void dictionary_unset(dictionary * d, char * key) |
| 451 | { |
| 452 | unsigned hash ; |
| 453 | int i ; |
| 454 | |
| 455 | hash = dictionary_hash(key); |
| 456 | for (i=0 ; i<d->size ; i++) { |
| 457 | if (d->key[i]==NULL) |
| 458 | continue ; |
| 459 | /* Compare hash */ |
| 460 | if (hash==d->hash[i]) { |
| 461 | /* Compare string, to avoid hash collisions */ |
| 462 | if (!strcmp(key, d->key[i])) { |
| 463 | /* Found key */ |
| 464 | break ; |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | if (i>=d->size) |
| 469 | /* Key not found */ |
| 470 | return ; |
| 471 | |
| 472 | free(d->key[i]); |
| 473 | d->key[i] = NULL ; |
| 474 | if (d->val[i]!=NULL) { |
| 475 | free(d->val[i]); |
| 476 | d->val[i] = NULL ; |
| 477 | } |
| 478 | d->hash[i] = 0 ; |
| 479 | d->n -- ; |
| 480 | return ; |
| 481 | } |
| 482 | |
| 483 | |
| 484 | /*-------------------------------------------------------------------------*/ |
no test coverage detected