MCPcopy Create free account
hub / github.com/F-Stack/f-stack / zslDelete

Function zslDelete

app/redis-6.2.6/src/t_zset.c:219–246  ·  view source on GitHub ↗

Delete an element with matching score/element from the skiplist. * The function returns 1 if the node was found and deleted, otherwise * 0 is returned. * * If 'node' is NULL the deleted node is freed by zslFreeNode(), otherwise * it is not freed (but just unlinked) and *node is set to the node pointer, * so that it is possible for the caller to reuse the node (including the * referenced SDS

Source from the content-addressed store, hash-verified

217 * so that it is possible for the caller to reuse the node (including the
218 * referenced SDS string at node->ele). */
219int zslDelete(zskiplist *zsl, double score, sds ele, zskiplistNode **node) {
220 zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x;
221 int i;
222
223 x = zsl->header;
224 for (i = zsl->level-1; i >= 0; i--) {
225 while (x->level[i].forward &&
226 (x->level[i].forward->score < score ||
227 (x->level[i].forward->score == score &&
228 sdscmp(x->level[i].forward->ele,ele) < 0)))
229 {
230 x = x->level[i].forward;
231 }
232 update[i] = x;
233 }
234 /* We may have multiple elements with the same score, what we need
235 * is to find the element with both the right score and object. */
236 x = x->level[0].forward;
237 if (x && score == x->score && sdscmp(x->ele,ele) == 0) {
238 zslDeleteNode(zsl, x, update);
239 if (!node)
240 zslFreeNode(x);
241 else
242 *node = x;
243 return 1;
244 }
245 return 0; /* not found */
246}
247
248/* Update the score of an element inside the sorted set skiplist.
249 * Note that the element must exist and must match 'score'.

Callers 1

zsetRemoveFromSkiplistFunction · 0.85

Calls 3

sdscmpFunction · 0.85
zslDeleteNodeFunction · 0.85
zslFreeNodeFunction · 0.85

Tested by

no test coverage detected