reuse existing range comparators in the zset (#8714)

There are 2 common range comparators for skiplist: zslValueGteMin and
zslValueLteMax, but they're not being reused in zslDeleteRangeByScore

This is a small change to make code cleaner.
This commit is contained in:
wuYin 2021-04-01 13:50:23 +08:00 committed by GitHub
parent 07f39ae47b
commit e5d50b236c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -388,9 +388,8 @@ unsigned long zslDeleteRangeByScore(zskiplist *zsl, zrangespec *range, dict *dic
x = zsl->header; x = zsl->header;
for (i = zsl->level-1; i >= 0; i--) { for (i = zsl->level-1; i >= 0; i--) {
while (x->level[i].forward && (range->minex ? while (x->level[i].forward &&
x->level[i].forward->score <= range->min : !zslValueGteMin(x->level[i].forward->score, range))
x->level[i].forward->score < range->min))
x = x->level[i].forward; x = x->level[i].forward;
update[i] = x; update[i] = x;
} }
@ -399,9 +398,7 @@ unsigned long zslDeleteRangeByScore(zskiplist *zsl, zrangespec *range, dict *dic
x = x->level[0].forward; x = x->level[0].forward;
/* Delete nodes while in range. */ /* Delete nodes while in range. */
while (x && while (x && zslValueLteMax(x->score, range)) {
(range->maxex ? x->score < range->max : x->score <= range->max))
{
zskiplistNode *next = x->level[0].forward; zskiplistNode *next = x->level[0].forward;
zslDeleteNode(zsl,x,update); zslDeleteNode(zsl,x,update);
dictDelete(dict,x->ele); dictDelete(dict,x->ele);