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

Function zslDeleteRangeByLex

src/t_zset.cpp:412–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412unsigned long zslDeleteRangeByLex(zskiplist *zsl, zlexrangespec *range, dict *dict) {
413 zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x;
414 unsigned long removed = 0;
415 int i;
416
417
418 x = zsl->header;
419 for (i = zsl->level-1; i >= 0; i--) {
420 while (x->level(i)->forward &&
421 !zslLexValueGteMin(x->level(i)->forward->ele,range))
422 x = x->level(i)->forward;
423 update[i] = x;
424 }
425
426 /* Current node is the last with score < or <= min. */
427 x = x->level(0)->forward;
428
429 /* Delete nodes while in range. */
430 while (x && zslLexValueLteMax(x->ele,range)) {
431 zskiplistNode *next = x->level(0)->forward;
432 zslDeleteNode(zsl,x,update);
433 dictDelete(dict,x->ele);
434 zslFreeNode(x); /* Here is where x->ele is actually released. */
435 removed++;
436 x = next;
437 }
438 return removed;
439}
440
441/* Delete all the elements with rank between start and end from the skiplist.
442 * Start and end are inclusive. Note that start and end need to be 1-based */

Callers 1

zremrangeGenericCommandFunction · 0.85

Calls 6

zslLexValueGteMinFunction · 0.85
zslLexValueLteMaxFunction · 0.85
zslDeleteNodeFunction · 0.85
zslFreeNodeFunction · 0.85
levelMethod · 0.80
dictDeleteFunction · 0.70

Tested by

no test coverage detected