当前位置:网站首页>[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 .
边栏推荐
- When MySQL imports data, it has been changed to CSV utf8 file and the file name is English. Why does it still fail to import
- DDD go practice
- 腾讯云数据库的可信可控之路
- 如何自动生成短链?如何在线批量生成带UTM参数的链接?
- Vivo official website app full model UI adaptation scheme
- C#Socket
- YUV422 to RGB (422sp to 420p)
- Babbitt | metauniverse daily must read: the popularity of virtual people has decreased, and some "debut is the peak", and the onlookers have dispersed
- C#Socket
- The role of the resize function is "suggestions collection"
猜你喜欢

Advanced technology management - how can the team be broken?

Face and key point detection: yolo5face practice

IJCAI2022开会了! 微软等《领域泛化Domain Generalization》教程

ag 搜索工具参数详解

When facing complex problems, systematic thinking helps you understand the essence of the problem

DDD go practice

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

Byte side: can TCP and UDP use the same port?

Sentinel vs Hystrix 限流对比,到底怎么选?
QT | learn about QT creator by creating a simple project
随机推荐
The noise reduction effect is increased by more than 6 times! With the microphone inside the headset, this wireless noise reduction headset is unusual!
C#Socket
零基础学习CANoe Panel(17)—— Panel CAPL Function
ES6 --- four powerful operators (?,? =,?.,?:)
kali修改更新源(无法安全的用该源更新)
When MySQL imports data, it has been changed to CSV utf8 file and the file name is English. Why does it still fail to import
测试用例和缺陷报告模板
C#程序设计的6大原则
CNN structural design skills: taking into account speed accuracy and engineering implementation
Face and key point detection: yolo5face practice
[fiddlertx plug-in] use Fiddler to capture the package Tencent classroom video download (unable to capture the package solution)
【面试:并发篇24:多线程:综合练习】顺序控制
Protobuf的简单使用
Fastjson deserialization vulnerability utilization analysis collection
Vivo official website app full model UI adaptation scheme
Array of arm disassembly
How to copy all files in one folder to another folder
QT | learn about QT creator by creating a simple project
数据库sql语句练习题「建议收藏」
Vivo official website app full model UI adaptation scheme