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

Function zsetRemoveFromSkiplist

src/t_zset.cpp:1460–1484  ·  view source on GitHub ↗

Deletes the element 'ele' from the sorted set encoded as a skiplist+dict, * returning 1 if the element existed and was deleted, 0 otherwise (the * element was not there). It does not resize the dict after deleting the * element. */

Source from the content-addressed store, hash-verified

1458 * element was not there). It does not resize the dict after deleting the
1459 * element. */
1460static int zsetRemoveFromSkiplist(zset *zs, sds ele) {
1461 dictEntry *de;
1462 double score;
1463
1464 de = dictUnlink(zs->dict,ele);
1465 if (de != NULL) {
1466 /* Get the score in order to delete from the skiplist later. */
1467 score = *(double*)dictGetVal(de);
1468
1469 /* Delete from the hash table and later from the skiplist.
1470 * Note that the order is important: deleting from the skiplist
1471 * actually releases the SDS string representing the element,
1472 * which is shared between the skiplist and the hash table, so
1473 * we need to delete from the skiplist as the final step. */
1474 dictFreeUnlinkedEntry(zs->dict,de);
1475
1476 /* Delete from skiplist. */
1477 int retval = zslDelete(zs->zsl,score,ele,NULL);
1478 serverAssert(retval);
1479
1480 return 1;
1481 }
1482
1483 return 0;
1484}
1485
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). */

Callers 2

zsetDelFunction · 0.85
zdiffAlgorithm2Function · 0.85

Calls 3

dictUnlinkFunction · 0.85
dictFreeUnlinkedEntryFunction · 0.85
zslDeleteFunction · 0.85

Tested by

no test coverage detected