Delete all the elements with rank between start and end from the skiplist. * Start and end are inclusive. Note that start and end need to be 1-based */
| 441 | /* Delete all the elements with rank between start and end from the skiplist. |
| 442 | * Start and end are inclusive. Note that start and end need to be 1-based */ |
| 443 | unsigned long zslDeleteRangeByRank(zskiplist *zsl, unsigned int start, unsigned int end, dict *dict) { |
| 444 | zskiplistNode *update[ZSKIPLIST_MAXLEVEL], *x; |
| 445 | unsigned long traversed = 0, removed = 0; |
| 446 | int i; |
| 447 | |
| 448 | x = zsl->header; |
| 449 | for (i = zsl->level-1; i >= 0; i--) { |
| 450 | while (x->level(i)->forward && (traversed + x->level(i)->span) < start) { |
| 451 | traversed += x->level(i)->span; |
| 452 | x = x->level(i)->forward; |
| 453 | } |
| 454 | update[i] = x; |
| 455 | } |
| 456 | |
| 457 | traversed++; |
| 458 | x = x->level(0)->forward; |
| 459 | while (x && traversed <= end) { |
| 460 | zskiplistNode *next = x->level(0)->forward; |
| 461 | zslDeleteNode(zsl,x,update); |
| 462 | dictDelete(dict,x->ele); |
| 463 | zslFreeNode(x); |
| 464 | removed++; |
| 465 | traversed++; |
| 466 | x = next; |
| 467 | } |
| 468 | return removed; |
| 469 | } |
| 470 | |
| 471 | /* Find the rank for an element by both score and key. |
| 472 | * Returns 0 when the element cannot be found, rank otherwise. |
no test coverage detected