"Redis Design and Implementation" chapter summary: jump table

Table 4. Jumping

Underlying implementation ordered set of keys to one of: when a more ordered set if the element contains the number of elements in the set are ordered or longer strings, use the jump table
as an internal data structure of the cluster nodes
hop in the table, only two use Redis

Table 4.1 Overview of jump

redis.h / zskiplistNode and two structures redis.h / zskiplist defined, zskiplistNode node represents a jump table, zskiplist jump table for storing node information, such as number of nodes, the head and tail pointers

Examples:
Here Insert Picture Description
As shown above, the leftmost is zskiplist structure, its properties explained as follows:
Here Insert Picture Description
the right to four zskiplistNode structure, its properties explained as follows:
Here Insert Picture Description
Let's look at specific analysis jump table node and hop tables

4.2 skip list node implements

redis.h / zskiplistNode:
Here Insert Picture Description
individually analyzed for the following properties

4.2.1 Layer:

Each time a new node is created, the program randomly generated according to a power law (the greater the probability of occurrence of the smaller number) of a value between 1 and 32 as the level array size (level []) is between, i.e. layer the height of

example:
Here Insert Picture Description

4.2.1.1 forward pointer

Each layer has a forward pointer pointing to the direction of the trailer, the header for access to the table from the direction of the end node

Examples: dotted lines indicate a path direction to the end of the table, the table jump traversing all nodes in the header
Here Insert Picture Description

4.2.1.2 Span

Span of each layer, for recording the distance between two nodes

Role: Not used to traverse operation, because only the forward pointer traversal operation can be; in fact is used to calculate the ranking is: in the process to find a node, span all layers will add up along the way visited, the result is that the target node resulting jump in the qualifying table

Examples: the dashed line labeled lookup score of 3.0 in the jump table, the members of the object is a node o3, experienced along the layer; As can be seen, the discovery process after only one layer, and a span of 3, the node ranking 3
Here Insert Picture Description

4.2.2 backward (BW) Pointer

For accessing from the head end of the table to the table node direction

The difference between the forward pointer: a pointer forward skip a plurality of nodes, each node as a plurality of layers, each layer has a forward pointer, it is not necessarily limited; The pointer can only retreat back to the previous node, since each only one node pointer Back

Examples: traversing from the head end of the table to the table, first positioned through the tail end of the list, and then back through the pointers to traverse
Here Insert Picture Description

4.2.3 scores and member objects

Members of the object must be unique, the score may be repeated; node value will follow the same members in the object to be sorted lexicographically in size, small front

4.3 jump table implementation

redis.h / zskiplist:
Here Insert Picture Description
Although alone can form a plurality of nodes a jump table jump table, a similar list, using a result zskiplist hold these nodes, the program can more easily jump table for the entire process, such as fast access headers and footers (O (1)), quick access number (length attribute, O (1)) table hop node, the number of layers quick access node with the highest (level, O (1), not including the header Note) and other information

example:
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/qq_41594698/article/details/94178725