Time complexity of zadd when value has score greater than highest score present in the targeted sorted set

丶灬走出姿态 提交于 2019-12-25 18:35:01

问题


If every value one adds to a sorted set (redis) is one with the highest score, will the time complexity be O(log(N)) for each zadd?

OR, for such edge cases, redis performs optimizations (e.g. an exception that in such cases where score is higher than the highest score in the set, simply add the value at the highest spot)?

Practically, I ask because I keep a global sorted set in my app where values are zadded with time since epoch as the score. And I'm wondering whether this will still be O(log(N)), or would it be faster?


回答1:


Once a Sorted Set has grown over the thresholds set by the zset-max-ziplist-* configuration directives, it is encoded as a skip list. Optimizing insertion for this edge case seems impossible due to the need to maintain the skip list's upper levels. A cursory review of the source code shows that, as expected, this isn't handled in any special way.



来源:https://stackoverflow.com/questions/40870081/time-complexity-of-zadd-when-value-has-score-greater-than-highest-score-present

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!