Redis 中 LTRIM 命令的时间复杂度是多少?
What is time complexity of the LTRIM command in Redis?
根据Redis文档,LTRIM
Redis命令的时间复杂度如下
Time complexity: O(N) where N is the number of elements to be removed
by the operation.
但是,我有些困惑。
比如链表有400个0到399的数,如果我LTRIM 0 99
,99到399的原始链节点我觉得没有必要访问。断开节点 99 和节点 100 之间的节点可能就足够了。
所以我认为 N 等于 100 而不是 300
请给我一个深刻的解释。
the raw linked node from 99 to 399 has no necessity to be visited I think
没有。这些节点需要一个一个的释放,所以时间复杂度是O(N),其中N是要移除的元素个数。
根据Redis文档,LTRIM
Redis命令的时间复杂度如下
Time complexity: O(N) where N is the number of elements to be removed by the operation.
但是,我有些困惑。
比如链表有400个0到399的数,如果我LTRIM 0 99
,99到399的原始链节点我觉得没有必要访问。断开节点 99 和节点 100 之间的节点可能就足够了。
所以我认为 N 等于 100 而不是 300
请给我一个深刻的解释。
the raw linked node from 99 to 399 has no necessity to be visited I think
没有。这些节点需要一个一个的释放,所以时间复杂度是O(N),其中N是要移除的元素个数。