§05 线性结构
跳表 Skip List
多层有序链表:上层是快速通道,查找逐层下沉、向右推进;插入抛硬币决定层高——Redis ZSet 的底层结构。
跳表 Skip List
伪代码
1
// 跳表插入
2
function insert(key):
3
node = 头哨兵; 更新路径记录
4
for level = 最高层 downto 0:
5
while node.right.key < key: node = node.right // 向右走
6
update[level] = node // 记录下沉点
7
node = node.down // 向下沉一层
8
随机层数 L(抛硬币)
9
for i = 0 to L: 在 update[i] 后接入新节点