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

Function zslFirstInRange

src/t_zset.cpp:330–352  ·  view source on GitHub ↗

Find the first 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

328/* Find the first node that is contained in the specified range.
329 * Returns NULL when no element is contained in the range. */
330zskiplistNode *zslFirstInRange(zskiplist *zsl, zrangespec *range) {
331 zskiplistNode *x;
332 int i;
333
334 /* If everything is out of range, return early. */
335 if (!zslIsInRange(zsl,range)) return NULL;
336
337 x = zsl->header;
338 for (i = zsl->level-1; i >= 0; i--) {
339 /* Go forward while *OUT* of range. */
340 while (x->level(i)->forward &&
341 !zslValueGteMin(x->level(i)->forward->score,range))
342 x = x->level(i)->forward;
343 }
344
345 /* This is an inner range, so the next node cannot be NULL. */
346 x = x->level(0)->forward;
347 serverAssert(x != NULL);
348
349 /* Check if score <= max. */
350 if (!zslValueLteMax(x->score,range)) return NULL;
351 return x;
352}
353
354/* Find the last node that is contained in the specified range.
355 * Returns NULL when no element is contained in the range. */

Callers 4

geoGetPointsInRangeFunction · 0.85
zcountCommandFunction · 0.85
zsetInitScoreRangeFunction · 0.85

Calls 4

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

Tested by

no test coverage detected