-
Notifications
You must be signed in to change notification settings - Fork 45.8k
【Redis为什么用跳表实现有序集合】章节元素查询步骤是否有多余 #2426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
看了下 Redis 的相关跳表的实现(参考 t_zset.c 中, zslInsert 函数):
可以看到如果分数相等的情况下 x->level[i].forward->score == score ,且元素值小于目标元素ele时继续循环,下降到下一级。而元素值等于ele,即sdscmp(x->level[i].forward->ele, ele) == 0,会跳出循环,直接返回结果(上述代码是修改,即先找到再修改) |
感谢指出👍 |
Redis为什么用跳表实现有序集合原文中关于元素查询的描述如下
我觉得在步骤2中,不是已经找到了节点8吗,为啥还要向下找,步骤3~步骤7是否是多余的。其次,步骤7中应该说的是判断 7 的后继,等于 8,查找结束,而不是前驱。
此外,前文手写一个跳表中,也有类似元素查询的举例,找到节点后,便不再向下查找了,这两处的元素查询步骤有所出入。
附原文链接如下:
JavaGuide/docs/database/redis/redis-skiplist.md
Line 282 in a88ad33
JavaGuide/docs/database/redis/redis-skiplist.md
Line 87 in a88ad33
The text was updated successfully, but these errors were encountered: