Find the rank for an element by both score and key. * Returns 0 when the element cannot be found, rank otherwise. * Note that the rank is 1-based due to the span of zsl->header to the * first element. */
| 473 | * Note that the rank is 1-based due to the span of zsl->header to the |
| 474 | * first element. */ |
| 475 | unsigned long zslGetRank(zskiplist *zsl, double score, sds ele) { |
| 476 | zskiplistNode *x; |
| 477 | unsigned long rank = 0; |
| 478 | int i; |
| 479 | |
| 480 | x = zsl->header; |
| 481 | for (i = zsl->level-1; i >= 0; i--) { |
| 482 | while (x->level[i].forward && |
| 483 | (x->level[i].forward->score < score || |
| 484 | (x->level[i].forward->score == score && |
| 485 | sdscmp(x->level[i].forward->ele,ele) <= 0))) { |
| 486 | rank += x->level[i].span; |
| 487 | x = x->level[i].forward; |
| 488 | } |
| 489 | |
| 490 | /* x might be equal to zsl->header, so test if obj is non-NULL */ |
| 491 | if (x->ele && sdscmp(x->ele,ele) == 0) { |
| 492 | return rank; |
| 493 | } |
| 494 | } |
| 495 | return 0; |
| 496 | } |
| 497 | |
| 498 | /* Finds an element by its rank. The rank argument needs to be 1-based. */ |
| 499 | zskiplistNode* zslGetElementByRank(zskiplist *zsl, unsigned long rank) { |
no test coverage detected