Delete an element from a hash. * Return 1 on deleted and 0 on not found. */
| 280 | /* Delete an element from a hash. |
| 281 | * Return 1 on deleted and 0 on not found. */ |
| 282 | int hashTypeDelete(robj *o, sds field) { |
| 283 | int deleted = 0; |
| 284 | |
| 285 | if (o->encoding == OBJ_ENCODING_ZIPLIST) { |
| 286 | unsigned char *zl, *fptr; |
| 287 | |
| 288 | zl = (unsigned char*)ptrFromObj(o); |
| 289 | fptr = ziplistIndex(zl, ZIPLIST_HEAD); |
| 290 | if (fptr != NULL) { |
| 291 | fptr = ziplistFind(zl, fptr, (unsigned char*)field, sdslen(field), 1); |
| 292 | if (fptr != NULL) { |
| 293 | zl = ziplistDelete(zl,&fptr); /* Delete the key. */ |
| 294 | zl = ziplistDelete(zl,&fptr); /* Delete the value. */ |
| 295 | o->m_ptr = zl; |
| 296 | deleted = 1; |
| 297 | } |
| 298 | } |
| 299 | } else if (o->encoding == OBJ_ENCODING_HT) { |
| 300 | if (dictDelete((dict*)ptrFromObj(o), field) == C_OK) { |
| 301 | deleted = 1; |
| 302 | |
| 303 | /* Always check if the dictionary needs a resize after a delete. */ |
| 304 | if (htNeedsResize((dict*)ptrFromObj(o))) dictResize((dict*)ptrFromObj(o)); |
| 305 | } |
| 306 | |
| 307 | } else { |
| 308 | serverPanic("Unknown hash encoding"); |
| 309 | } |
| 310 | return deleted; |
| 311 | } |
| 312 | |
| 313 | /* Return the number of elements in a hash. */ |
| 314 | unsigned long hashTypeLength(robj_roptr o) { |
no test coverage detected