Find the first node that is contained in the specified lex range. * Returns NULL when no element is contained in the range. */
| 666 | /* Find the first node that is contained in the specified lex range. |
| 667 | * Returns NULL when no element is contained in the range. */ |
| 668 | zskiplistNode *zslFirstInLexRange(zskiplist *zsl, zlexrangespec *range) { |
| 669 | zskiplistNode *x; |
| 670 | int i; |
| 671 | |
| 672 | /* If everything is out of range, return early. */ |
| 673 | if (!zslIsInLexRange(zsl,range)) return NULL; |
| 674 | |
| 675 | x = zsl->header; |
| 676 | for (i = zsl->level-1; i >= 0; i--) { |
| 677 | /* Go forward while *OUT* of range. */ |
| 678 | while (x->level(i)->forward && |
| 679 | !zslLexValueGteMin(x->level(i)->forward->ele,range)) |
| 680 | x = x->level(i)->forward; |
| 681 | } |
| 682 | |
| 683 | /* This is an inner range, so the next node cannot be NULL. */ |
| 684 | x = x->level(0)->forward; |
| 685 | serverAssert(x != NULL); |
| 686 | |
| 687 | /* Check if score <= max. */ |
| 688 | if (!zslLexValueLteMax(x->ele,range)) return NULL; |
| 689 | return x; |
| 690 | } |
| 691 | |
| 692 | /* Find the last node that is contained in the specified range. |
| 693 | * Returns NULL when no element is contained in the range. */ |
no test coverage detected