Find the last node that is contained in the specified range. * Returns NULL when no element is contained in the range. */
| 354 | /* Find the last node that is contained in the specified range. |
| 355 | * Returns NULL when no element is contained in the range. */ |
| 356 | zskiplistNode *zslLastInRange(zskiplist *zsl, zrangespec *range) { |
| 357 | zskiplistNode *x; |
| 358 | int i; |
| 359 | |
| 360 | /* If everything is out of range, return early. */ |
| 361 | if (!zslIsInRange(zsl,range)) return NULL; |
| 362 | |
| 363 | x = zsl->header; |
| 364 | for (i = zsl->level-1; i >= 0; i--) { |
| 365 | /* Go forward while *IN* range. */ |
| 366 | while (x->level(i)->forward && |
| 367 | zslValueLteMax(x->level(i)->forward->score,range)) |
| 368 | x = x->level(i)->forward; |
| 369 | } |
| 370 | |
| 371 | /* This is an inner range, so this node cannot be NULL. */ |
| 372 | serverAssert(x != NULL); |
| 373 | |
| 374 | /* Check if score >= min. */ |
| 375 | if (!zslValueGteMin(x->score,range)) return NULL; |
| 376 | return x; |
| 377 | } |
| 378 | |
| 379 | /* Delete all the elements with score between min and max from the skiplist. |
| 380 | * Both min and max can be inclusive or exclusive (see range->minex and |
no test coverage detected