Redis链表
数据结构
- redis的链表就是基础的双向链表
- TODO
迭代器
链表的迭代和数据是分开的,采用了类似迭代器模式,这个思想呗用到很多场景,如leveldb中。
可以参考一下迭代的设计模型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
typedef struct listIter { listNode *next; int direction; } listIter; listIter *listGetIterator(list *list, int direction) { listIter *iter; if ((iter = zmalloc(sizeof(*iter))) == NULL) return NULL; if (direction == AL_START_HEAD) iter->next = list->head; else iter->next = list->tail; iter->direction = direction; return iter; }