前瞻
skip-list是一个可快速线性搜索logn的、依靠随机算法的、并发友好的、有序的链表
测试表明,相比于红黑树或者AVL树,跳表的内存占用更高,查找的时间复杂度更高
历史
Normally, the sequential array supports binary search, while the linked list does not, as the array supports accessing data by index but linked list not.
So the skip list actually is a list with binary search feature. How to do that?
Add a new index link list on the base of original link list
When u wanna get the data 7, using original list u need to traverse 7 times, but using the 1st index, u just need 4 times.
实现
只有最下层的链表具有完整的数据, 上面的链表都是索引链
level
在插入节点时, 会根据概率判断需不需要在某一level插入这个节点:
以maxHeight=12(官方推荐),为例,可以得到height为1-12的概率:
| 层高 | 概率 |
|---|---|
| 1 | 0.75 |
| 2 | 0.1875 |
| 3 | 0.046875 |
| 4 | 0.0117188 |
| 5 | 0.00292969 |
| 6 | 0.000732422 |
| 7 | 0.000183105 |
| 8 | 4.57764e-05 |
| 9 | 1.14441e-05 |
| 10 | 2.86102e-06 |
| 11 | 7.15256e-07 |
| 12 | 1.78814e-07 |
Ref
- https://byte_dance.fei_shu.cn/wiki/wikcnUF6dMWnO1EGNaCJzO4HXKg
- https://tech.byte_dance.net/articles/6798863476430209031
- https://byte_dance.fei_shu.cn/wiki/wikcnUF6dMWnO1EGNaCJzO4HXKg#tolsED