Commit 2f282aee authored by antirez's avatar antirez
Browse files

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.
parent 29226a39
...@@ -281,8 +281,8 @@ zskiplistNode *zslUpdateScore(zskiplist *zsl, double curscore, sds ele, double n ...@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment