MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / hashTypeDelete

Function hashTypeDelete

src/t_hash.cpp:282–311  ·  view source on GitHub ↗

Delete an element from a hash. * Return 1 on deleted and 0 on not found. */

Source from the content-addressed store, hash-verified

280/* Delete an element from a hash.
281 * Return 1 on deleted and 0 on not found. */
282int 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. */
314unsigned long hashTypeLength(robj_roptr o) {

Callers 4

hdelCommandFunction · 0.85
hrenameCommandFunction · 0.85
activeExpireCycleExpireFunction · 0.85
RM_HashSetFunction · 0.85

Calls 8

ptrFromObjFunction · 0.85
ziplistIndexFunction · 0.85
ziplistFindFunction · 0.85
sdslenFunction · 0.85
ziplistDeleteFunction · 0.85
htNeedsResizeFunction · 0.85
dictResizeFunction · 0.85
dictDeleteFunction · 0.70

Tested by

no test coverage detected