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

Function zslDeleteRangeByScore

src/t_zset.cpp:384–410  ·  view source on GitHub ↗

Delete all the elements with score between min and max from the skiplist. * Both min and max can be inclusive or exclusive (see range->minex and * range->maxex). When inclusive a score >= min && score <= max is deleted. * Note that this function takes the reference to the hash table view of the * sorted set, in order to remove the elements from the hash table too. */

Source from the content-addressed store, hash-verified

382 * Note that this function takes the reference to the hash table view of the
383 * sorted set, in order to remove the elements from the hash table too. */
384unsigned long zslDeleteRangeByScore(zskiplist *zsl, zrangespec *range, dict *dict) {
385 zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x;
386 unsigned long removed = 0;
387 int i;
388
389 x = zsl->header;
390 for (i = zsl->level-1; i >= 0; i--) {
391 while (x->level(i)->forward &&
392 !zslValueGteMin(x->level(i)->forward->score, range))
393 x = x->level(i)->forward;
394 update[i] = x;
395 }
396
397 /* Current node is the last with score < or <= min. */
398 x = x->level(0)->forward;
399
400 /* Delete nodes while in range. */
401 while (x && zslValueLteMax(x->score, range)) {
402 zskiplistNode *next = x->level(0)->forward;
403 zslDeleteNode(zsl,x,update);
404 dictDelete(dict,x->ele);
405 zslFreeNode(x); /* Here is where x->ele is actually released. */
406 removed++;
407 x = next;
408 }
409 return removed;
410}
411
412unsigned long zslDeleteRangeByLex(zskiplist *zsl, zlexrangespec *range, dict *dict) {
413 zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x;

Callers 1

zremrangeGenericCommandFunction · 0.85

Calls 6

zslValueGteMinFunction · 0.85
zslValueLteMaxFunction · 0.85
zslDeleteNodeFunction · 0.85
zslFreeNodeFunction · 0.85
levelMethod · 0.80
dictDeleteFunction · 0.70

Tested by

no test coverage detected