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

Function zslGetElementByRank

src/t_zset.cpp:499–516  ·  view source on GitHub ↗

Finds an element by its rank. The rank argument needs to be 1-based. */

Source from the content-addressed store, hash-verified

497
498/* Finds an element by its rank. The rank argument needs to be 1-based. */
499zskiplistNode* zslGetElementByRank(zskiplist *zsl, unsigned long rank) {
500 zskiplistNode *x;
501 unsigned long traversed = 0;
502 int i;
503
504 x = zsl->header;
505 for (i = zsl->level-1; i >= 0; i--) {
506 while (x->level(i)->forward && (traversed + x->level(i)->span) <= rank)
507 {
508 traversed += x->level(i)->span;
509 x = x->level(i)->forward;
510 }
511 if (traversed == rank) {
512 return x;
513 }
514 }
515 return NULL;
516}
517
518/* Populate the rangespec according to the objects min and max. */
519static int zslParseRange(robj *min, robj *max, zrangespec *spec) {

Callers 2

sortCommandFunction · 0.85

Calls 1

levelMethod · 0.80

Tested by

no test coverage detected