当前位置:网站首页>[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 .
边栏推荐
- How to copy all files in one folder to another folder
- 接口测试工具 restlet client
- Cesium polygon gradient texture (canvas)
- Pyg tutorial (8): calculate a more efficient sparse matrix form
- Test cases and defect report templates
- 零基础学习CANoe Panel(17)—— Panel CAPL Function
- How to choose sentinel vs. hystrix current limiting?
- Decompile app
- Talk about what's going on with C # backstage GC?
- 测试用例和缺陷报告模板
猜你喜欢

GPON介绍及华为OLT网关注册配置流程

Web3 entrepreneurship has all the elements of explosive growth of innovation

DDD go practice

五、品达通用权限系统__pd-tools-xxs(防跨站脚本攻击)

MySQL master-slave configuration

ONEFLOW V0.8.0 officially released

Face and key point detection: yolo5face practice

In depth understanding of seven specific ways to enhance code scalability

How will Web3 change the future of people?

How to solve the problem of high concurrency and large traffic with PHP
随机推荐
How to copy all files in one folder to another folder
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
Sqlx library usage
Interface testing tool restlet client
C#程序设计的6大原则
如何自动生成短链?如何在线批量生成带UTM参数的链接?
Vivo official website app full model UI adaptation scheme
[ManageEngine] value brought by Siem to enterprises
Airtest解决“自动装包”过程中需要输入密码的问题(同适用于随机弹框处理)
黑盒(功能)测试基本方法
The inexplicability of Intel disassembly
Fusing and degrading Sentinel
Huawei occupies half of the folding mobile phone market, proving its irreplaceable position in the high-end market
Isn't it too much to play Gobang in idea?
ONEFLOW V0.8.0 officially released
ag 搜索工具参数详解
[interview: concurrent Article 23: multithreading: Join] re understanding of join
2022 latest examination questions and answers of eight members (standard staff) of Shanghai Architecture
When facing complex problems, systematic thinking helps you understand the essence of the problem
mysql导入数据时已改成csv utf8文件且文件名为英文,为什么还是导入失败