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

Function zsetDel

src/t_zset.cpp:1488–1506  ·  view source on GitHub ↗

Delete the element 'ele' from the sorted set, returning 1 if the element * existed and was deleted, 0 otherwise (the element was not there). */

Source from the content-addressed store, hash-verified

1486/* Delete the element 'ele' from the sorted set, returning 1 if the element
1487 * existed and was deleted, 0 otherwise (the element was not there). */
1488int zsetDel(robj *zobj, sds ele) {
1489 if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
1490 unsigned char *eptr;
1491
1492 if ((eptr = zzlFind((unsigned char*)zobj->m_ptr,ele,NULL)) != NULL) {
1493 zobj->m_ptr = zzlDelete((unsigned char*)zobj->m_ptr,eptr);
1494 return 1;
1495 }
1496 } else if (zobj->encoding == OBJ_ENCODING_SKIPLIST) {
1497 zset *zs = (zset*)ptrFromObj(zobj);
1498 if (zsetRemoveFromSkiplist(zs, ele)) {
1499 if (htNeedsResize(zs->dict)) dictResize(zs->dict);
1500 return 1;
1501 }
1502 } else {
1503 serverPanic("Unknown sorted set encoding");
1504 }
1505 return 0; /* No such element found. */
1506}
1507
1508/* Given a sorted set object returns the 0-based rank of the object or
1509 * -1 if the object does not exist.

Callers 4

zremCommandFunction · 0.85
genericZpopCommandFunction · 0.85
activeExpireCycleExpireFunction · 0.85
RM_ZsetRemFunction · 0.85

Calls 6

zzlFindFunction · 0.85
zzlDeleteFunction · 0.85
ptrFromObjFunction · 0.85
zsetRemoveFromSkiplistFunction · 0.85
htNeedsResizeFunction · 0.85
dictResizeFunction · 0.85

Tested by

no test coverage detected