Fix zslUpdateScore() edge case.

When the element new score is the same of prev/next node, the
lexicographical order kicks in, so we can safely update the node in
place only when the new score is strictly between the adjacent nodes
but never equal to one of them.

Technically speaking we could do extra checks to make sure that even if the
score is the same as one of the adjacent nodes, we can still update on
place, but this rarely happens, so probably not a good deal to make it
more complex.

Related to #5179.
This commit is contained in:
antirez 2018-08-01 19:01:40 +02:00
parent 29226a3919
commit 2f282aee0b

View File

@ -281,8 +281,8 @@ zskiplistNode *zslUpdateScore(zskiplist *zsl, double curscore, sds ele, double n
/* If the node, after the score update, would be still exactly /* If the node, after the score update, would be still exactly
* at the same position, we can just update the score without * at the same position, we can just update the score without
* actually removing and re-inserting the element in the skiplist. */ * actually removing and re-inserting the element in the skiplist. */
if ((x->backward == NULL || x->backward->score <= newscore) && if ((x->backward == NULL || x->backward->score < newscore) &&
(x->level[0].forward == NULL || x->level[0].forward->score >= newscore)) (x->level[0].forward == NULL || x->level[0].forward->score > newscore))
{ {
x->score = newscore; x->score = newscore;
return x; return x;