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

Function zslLastInRange

src/t_zset.cpp:356–377  ·  view source on GitHub ↗

Find the last node that is contained in the specified range. * Returns NULL when no element is contained in the range. */

Source from the content-addressed store, hash-verified

354/* Find the last node that is contained in the specified range.
355 * Returns NULL when no element is contained in the range. */
356zskiplistNode *zslLastInRange(zskiplist *zsl, zrangespec *range) {
357 zskiplistNode *x;
358 int i;
359
360 /* If everything is out of range, return early. */
361 if (!zslIsInRange(zsl,range)) return NULL;
362
363 x = zsl->header;
364 for (i = zsl->level-1; i >= 0; i--) {
365 /* Go forward while *IN* range. */
366 while (x->level(i)->forward &&
367 zslValueLteMax(x->level(i)->forward->score,range))
368 x = x->level(i)->forward;
369 }
370
371 /* This is an inner range, so this node cannot be NULL. */
372 serverAssert(x != NULL);
373
374 /* Check if score >= min. */
375 if (!zslValueGteMin(x->score,range)) return NULL;
376 return x;
377}
378
379/* Delete all the elements with score between min and max from the skiplist.
380 * Both min and max can be inclusive or exclusive (see range->minex and

Callers 3

zcountCommandFunction · 0.85
zsetInitScoreRangeFunction · 0.85

Calls 4

zslIsInRangeFunction · 0.85
zslValueLteMaxFunction · 0.85
zslValueGteMinFunction · 0.85
levelMethod · 0.80

Tested by

no test coverage detected