当前位置:网站首页>Getting started with redis - Chapter 4 - data structures and objects - jump table
Getting started with redis - Chapter 4 - data structures and objects - jump table
2022-06-23 11:44:00 【tiger’s bytes】
Skip list (skiplist) Is an ordered data structure , It maintains multiple pointers to other nodes in each node , So as to achieve the purpose of fast access to nodes .Redis Using the jump table as one of the underlying implementations of the ordered set key , If an ordered set contains more elements , Or members of elements in an ordered collection (member) When it's a long string ,Reids Will use the jump table as the underlying implementation of the ordered set key .
And the list 、 Data structures such as dictionaries are widely used in Redis It's different inside ,Redis There are only two places where the jump table is used , One is to implement an ordered set key , The other is used as internal data structure in cluster nodes .
The realization of jump table :
Redis The jump table is made up of redis.h/zskiplistNode and redis.h/zskiplist Two structural definitions :
typedef struct zskiplistNode {
struct zskiplistLevel {
struct zskiplistNode *forward; // Forward pointer
unsigned int span; // span
}level[];
struct zskiplistNode *backward; // Back pointer
double score; // The score is
robj *obj; // member object
}zskiplistNode;typedef struct zskiplist {
struct zskiplistNode *header, *tail; // Pointer to header node and footer node
unsigned long length; // Number of nodes in the table ( Header nodes are not counted )
int level; // The maximum number of layers in the table ( Header nodes are not counted )
}- layer : Jump table node level Arrays can contain multiple elements , Each element contains a pointer to other nodes , Programs can use these layers to speed up access to other nodes , Generally speaking , The more layers there are , The faster you can access other nodes . Every time a new jump table node is created , The program is based on the power law ( The larger the number, the smaller the probability of occurrence ) Randomly generate an interval between 1 ~ 32 The value between is taken as level Size of array , This is the height of the floor .
- Forward pointer : Each layer has a forward pointer to the end of the table (level[i].forward attribute ), Used to access nodes from header to footer .
- span :(level[i].span) Used to record the distance between two nodes , Span is used to calculate the rank of nodes , In the process of finding a node , Add up the spans of all layers visited along the way , The result is the position of the target node in the jump table .
- Back pointer : Used to access nodes from the end of the table to the head .
- Scores and members : The nodes in the jump table are arranged from small to large according to the score , The member object is a pointer , Point to a string object , The string object holds a SDS value .
In the same jump table , The member objects saved by each node must be unique , But the scores saved by the node can be the same , Nodes with the same score will be sorted by the size of the member objects in the dictionary order .

边栏推荐
猜你喜欢
随机推荐
Tensorrt notes (4) Modèle de segmentation du raisonnement
想学习eTS开发?教你开发一款IQ-EQ测试应用
KDD 2022 | 基于分层图扩散学习的癫痫波预测
Face the future calmly and strive to improve yourself
How many days is the general term of financial products?
mysql,如何在使用存储过程计算最大值
如何使用笔记软件 FlowUs、Notion 进行间隔重复?基于公式模版
电容参数哪里找!?
1路百兆光纤收发器1百兆光1百兆电桌面式以太网光纤收发器内置电源
Redis 入门-第二篇-数据结构与对象-链表
Voice data annotation tools and platforms
5 个关于 NFT 的技术漏洞
汉源高科新一代绿色节能以太网接入工业交换机高效节能型千兆工业以太网交换机
EasyGBS如何解决对讲功能使用异常?
The country has entered the main flood season. The Ministry of transport: the lines that do not meet the conditions for safe operation will be resolutely shut down!
Mobile securities account opening transaction? Is it safe to open an account online now?
十大劵商如何开户?在线开户安全么?
语音数据标注工具与平台
切比雪夫不等式证明及应用
不止于观测|阿里云可观测套件正式发布








[email protected] HDMI2.0光端机 HDMI高清视频光端机"/>