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

Function zslLastInLexRange

src/t_zset.cpp:694–715  ·  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

692/* Find the last node that is contained in the specified range.
693 * Returns NULL when no element is contained in the range. */
694zskiplistNode *zslLastInLexRange(zskiplist *zsl, zlexrangespec *range) {
695 zskiplistNode *x;
696 int i;
697
698 /* If everything is out of range, return early. */
699 if (!zslIsInLexRange(zsl,range)) return NULL;
700
701 x = zsl->header;
702 for (i = zsl->level-1; i >= 0; i--) {
703 /* Go forward while *IN* range. */
704 while (x->level(i)->forward &&
705 zslLexValueLteMax(x->level(i)->forward->ele,range))
706 x = x->level(i)->forward;
707 }
708
709 /* This is an inner range, so this node cannot be NULL. */
710 serverAssert(x != NULL);
711
712 /* Check if score >= min. */
713 if (!zslLexValueGteMin(x->ele,range)) return NULL;
714 return x;
715}
716
717/*-----------------------------------------------------------------------------
718 * Ziplist-backed sorted set API

Callers 3

zlexcountCommandFunction · 0.85
zsetInitLexRangeFunction · 0.85

Calls 4

zslIsInLexRangeFunction · 0.85
zslLexValueLteMaxFunction · 0.85
zslLexValueGteMinFunction · 0.85
levelMethod · 0.80

Tested by

no test coverage detected