当前位置:网站首页>[redis underlying parsing] linked list type
[redis underlying parsing] linked list type
2022-07-25 21:36:00 【Xiaosheng Fanyi】
Linked list
Linked list provides efficient node rearrangement capability , And sequential node access , And you can flexibly adjust the length of the linked list by adding and deleting nodes .
The list is in redis Is also widely used , For example, publish and subscribe , The slow query , Linked lists are also used in functions such as monitors . It also uses a linked list to store the status information of multiple clients , And using linked list to build client output buffer (output buffer).
1. The realization of linked list and linked list node
Each linked list node uses one adlist.h/listNode Structure to express :
typedef struct listNode{
struct listNode *prev; // Front node
struct listNode *next; // Post node
void *value; // The value of the node
}listNode;
Multiple listNode Can pass prev and next The hands make up Double ended linked list
As shown in the figure below 
Although only multiple listNode Structure can form a linked list , But with adlist.h/list To hold the list , It will be more convenient to operate .
typedef struct list{
listNode *head; // header node
listNode *tail; // Tail node
unsigned long len; // Number of nodes in the list
void *(*dup)(void *ptr); // Node value copy function
void *(*free)(void *ptr); // Node value release function
int (*match)(void *ptr,void *key); // Node value comparison function
}list;
list The structure provides a pointer to the head of the linked list head, Tail pointer tail, And chain length counter len.
dup,free and match Members are type specific functions used to implement polymorphic linked lists .
- dup Used to copy the value saved by the linked list node
- free Function is used to release the value saved by the linked list node
- match Function is used to compare whether the value maintained by the linked list node is equal to another input value

2. The characteristics of linked list
- Two ends : Link list nodes with
prevandnextThe pointer , The complexity of obtaining the pre node and post node of a node is O(1) - acyclic : Of the header node
prevPointer and tail nodenextThe hands all point to NULL, Access to the linked list NULL End point . - With head pointer and tail pointer : adopt
listThe structure andhead The pointerandtail The pointer, The complexity of getting the header node and the tail node of the linked list is O(1) - With linked list length counter : Program usage list Structural
len attributeCome onlistCount the number of linked list nodes held , The complexity of the program to obtain the number of nodes in the linked list is also O(1) - polymorphic : Link list node use
void*Pointer to save the node value , And through list Structural dup,free,match Three properties set type specific functions for node values , So linked lists can be used to hold different types of values .
边栏推荐
- 人脸与关键点检测:YOLO5Face实战
- NPM module removal_ [solved] after NPM uninstalls the module, the module is not removed from package.json [easy to understand]
- pyqt5使用pyqtgraph绘制多个Y值散点图
- [fiddlertx plug-in] use Fiddler to capture the package Tencent classroom video download (unable to capture the package solution)
- 我也是醉了,Eureka 延迟注册还有这个坑!
- cts测试步骤(卡西欧cts200测试)
- Byte side: can TCP and UDP use the same port?
- [interview: concurrent Part 24: multithreading: comprehensive exercise] sequence control
- Decompile app
- CNN structural design skills: taking into account speed accuracy and engineering implementation
猜你喜欢

函数栈帧的创建和销毁
![PHP zero time task, PHP laravel time task schedule [dry goods]](/img/09/c9a4c83fe23c852aa76a6f5a6cea52.png)
PHP zero time task, PHP laravel time task schedule [dry goods]

Oxford University: many common insomnia drugs lack long-term safety data

JMeter distributed pressure measurement

Web3 entrepreneurship has all the elements of explosive growth of innovation

Oracle RAC RMAN backup error ora-19501 ora-15081

Vivo official website app full model UI adaptation scheme

Stm3 (cubeide) lighting experiment

Per capita Swiss number series, Swiss number 4 generation JS reverse analysis

Detailed explanation of Ag search tool parameters
随机推荐
Vivo official website app full model UI adaptation scheme
An interview question about interface and implementation in golang
919. Complete binary tree inserter: simple BFS application problem
All non isomorphic subgraphs of a directed complete graph of order 3 (number of different hook graphs)
Kali modify the update source (it is not safe to update with this source)
Reading the pointpillar code of openpcdet -- Part 3: Calculation of loss function
Programmer's Guide to health quenching 5: introduction to sports Basics
Oracle RAC RMAN backup error ora-19501 ora-15081
C#Socket
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
Pyg tutorial (8): calculate a more efficient sparse matrix form
性能调试 -- Chrome Performance
2022 latest examination questions and answers of eight members (standard staff) of Shanghai Architecture
Airtest solves the problem that a password needs to be entered in the process of "automatic packaging" (the same applies to random bullet frame processing)
CTS test steps (Casio cts200 test)
Mysql8.0 MHA to achieve high availability "MHA"
【面试:并发篇23:多线程:join】join再理解
SSH private key realizes login to remote target server
测试用例和缺陷报告模板
How to evaluate hardware resources (number of CPUs, memory size) when Oracle migrates from small computers to x86 architecture? Is there a measurement index or company?