Search and remove an element. This is an helper function for * dictDelete() and dictUnlink(), please check the top comment * of those functions. */
| 389 | * dictDelete() and dictUnlink(), please check the top comment |
| 390 | * of those functions. */ |
| 391 | static dictEntry *dictGenericDelete(dict *d, const void *key, int nofree) { |
| 392 | uint64_t h, idx; |
| 393 | dictEntry *he, *prevHe; |
| 394 | int table; |
| 395 | |
| 396 | if (d->ht[0].used == 0 && d->ht[1].used == 0) return NULL; |
| 397 | |
| 398 | if (dictIsRehashing(d)) _dictRehashStep(d); |
| 399 | h = dictHashKey(d, key); |
| 400 | |
| 401 | for (table = 0; table <= 1; table++) { |
| 402 | idx = h & d->ht[table].sizemask; |
| 403 | he = d->ht[table].table[idx]; |
| 404 | prevHe = NULL; |
| 405 | while(he) { |
| 406 | if (key==he->key || dictCompareKeys(d, key, he->key)) { |
| 407 | /* Unlink the element from the list */ |
| 408 | if (prevHe) |
| 409 | prevHe->next = he->next; |
| 410 | else |
| 411 | d->ht[table].table[idx] = he->next; |
| 412 | if (!nofree) { |
| 413 | dictFreeKey(d, he); |
| 414 | dictFreeVal(d, he); |
| 415 | zfree(he); |
| 416 | } |
| 417 | d->ht[table].used--; |
| 418 | return he; |
| 419 | } |
| 420 | prevHe = he; |
| 421 | he = he->next; |
| 422 | } |
| 423 | if (!dictIsRehashing(d)) break; |
| 424 | } |
| 425 | return NULL; /* not found */ |
| 426 | } |
| 427 | |
| 428 | /* Remove an element, returning DICT_OK on success or DICT_ERR if the |
| 429 | * element was not found. */ |
no test coverage detected