Introduction
Redis implements a two-way linked list containing an iterator. The basic function is a universal two-way linked list. The source code implementation is worth reading the following.
Source File
Adlist. h adlist. c
Analysis
Here we will mainly introduce its main data structure and other linked list-related operations. If you are interested, you can view the source code by yourself. There are still a lot of tricky details.
/* Node, list, And iterator are the only data structures used currently. * // ** linked list node */typedef struct listnode {// struct listnode * Prev; // subsequent node struct listnode * Next; // value void * value ;} listnode;/** linked list iterator */typedef struct listiter {// next node listnode * Next; // iteration direction int ction;} listiter; /** linked list */typedef struct list {// header pointer listnode * head; // table tail pointer listnode * tail; // number of nodes unsigned long Len; // copy function void * (* DUP) (void * PTR); // release function void (* free) (void * PTR); // Compare function int (* match) (void * PTR, void * Key);} List;