redis list

结构

reids的list采用的是双向链表的实现,未使用dummy node。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
typedef struct listNode {
struct listNode *prev;
struct listNode *next;
void *value;
} listNode;

typedef struct listIter {
listNode *next;
int direction;
} listIter;

typedef struct list {
listNode *head;
listNode *tail;
// 节点值复制函数
void *(*dup)(void *ptr);
// 节点值释放函数
void (*free)(void *ptr);
// 节点值对比函数
int (*match)(void *ptr, void *key);
unsigned long len;
} list;

特点

  • 双端
  • 无环
  • 有头尾指针
  • 有长度计数器
  • 多态(使用void*来保存节点值,并提供freedupmatch来处理节点)