Find the first node that is contained in the specified range. * Returns NULL when no element is contained in the range. */
| 328 | /* Find the first node that is contained in the specified range. |
| 329 | * Returns NULL when no element is contained in the range. */ |
| 330 | zskiplistNode *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. */ |
no test coverage detected