mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
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:
parent
29226a3919
commit
2f282aee0b
@ -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
|
||||
* at the same position, we can just update the score without
|
||||
* actually removing and re-inserting the element in the skiplist. */
|
||||
if ((x->backward == NULL || x->backward->score <= newscore) &&
|
||||
(x->level[0].forward == NULL || x->level[0].forward->score >= newscore))
|
||||
if ((x->backward == NULL || x->backward->score < newscore) &&
|
||||
(x->level[0].forward == NULL || x->level[0].forward->score > newscore))
|
||||
{
|
||||
x->score = newscore;
|
||||
return x;
|
||||
|
Loading…
Reference in New Issue
Block a user