源码中关于复杂度的错误
I was looking at the implementation of the jump table in Redis, and I found that the complexity record in the comments is problematic. * T = O(N) */ int zslRandomLevel(void) { int level = 1; while ((random() & 0xFFFF) < (ZSKIPLIST_P * 0xFFFF)) level += 1; return (level < ZSKIPLIST_MAXLEVEL) ? level : ZSKIPLIST_MAXLEVEL; } The complexity here is O(N), but it should be O(ZSKIPLIST_MAXLEVEL). Since the complexity calculation in the algorithm ignores constants, the complexity of this function is actually O(1), of course, assuming that the complexity of random is O(1). The insertion and deletion of the skip list in the code are both O(Nlog(N)), and the complexity of searching is O(log(N)). However, the complexity of insertion and searching in the skip list is actually the same, both are O(log(N)) at best and O(N) at worst. The Wikipedia also has this information, and I hope you can change it.
内容来源: huangzworks/redis-3.0-annotated