Search and remove an element */
| 192 | |
| 193 | /* Search and remove an element */ |
| 194 | static int dictDelete(dict *ht, const void *key) { |
| 195 | unsigned int h; |
| 196 | dictEntry *de, *prevde; |
| 197 | |
| 198 | if (ht->size == 0) |
| 199 | return DICT_ERR; |
| 200 | h = dictHashKey(ht, key) & ht->sizemask; |
| 201 | de = ht->table[h]; |
| 202 | |
| 203 | prevde = NULL; |
| 204 | while(de) { |
| 205 | if (dictCompareHashKeys(ht,key,de->key)) { |
| 206 | /* Unlink the element from the list */ |
| 207 | if (prevde) |
| 208 | prevde->next = de->next; |
| 209 | else |
| 210 | ht->table[h] = de->next; |
| 211 | |
| 212 | dictFreeEntryKey(ht,de); |
| 213 | dictFreeEntryVal(ht,de); |
| 214 | hi_free(de); |
| 215 | ht->used--; |
| 216 | return DICT_OK; |
| 217 | } |
| 218 | prevde = de; |
| 219 | de = de->next; |
| 220 | } |
| 221 | return DICT_ERR; /* not found */ |
| 222 | } |
| 223 | |
| 224 | /* Destroy an entire hash table */ |
| 225 | static int _dictClear(dict *ht) { |
no test coverage detected