请选择 进入手机版 | 继续访问电脑版

Redis中国用户组(CRUG)论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
热搜: 活动 交友 discuz
查看: 4813|回复: 0

Redis源码分析(二)--结构体分析(1)

[复制链接]
  • TA的每日心情
    开心
    2017-8-30 15:46
  • 签到天数: 94 天

    [LV.6]常住居民II

    371

    主题

    481

    帖子

    3831

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    3831

    最佳新人活跃会员宣传达人突出贡献优秀版主荣誉管理论坛元老

    发表于 2016-3-29 12:09:30 | 显示全部楼层 |阅读模式

    继上次的redis源码分析(一)之后,本人开始订制着一份非常伟大的计划-啃完redis源代码,也对他进行了切块划分,鉴于本人目前对他的整个运行流畅还不特别清楚的情况下,所以决定第一个要解决的就是与逻辑无关的代码,也就是一些基本模块,因为是相互独立的,所以不会影响整体的阅读,所以第一个开刀的就是结构体模块了。结构体模块我划分了差不多10个文件的样子,今天看的主要是adlist.c的文件,收获有如下

    1.真心的帮我把数据结构的链表操作复习了一遍

    2.还有给人感觉最深的就是函数编程的思想无处不在,并没有明确的数据类型,结构体里的各种函数指针的调用,函数作为参数存在的频率非常高

    3.让我见识到了C语言中迭代器还能这么写,像用过高级语言的java,C#语言的同学肯定感觉迭代器Iterator嘛,不很简单嘛,一句话的事呗,但是C语言中没有现成的方法,怎么实现,adlist.c给我们提供了一种很简洁的写法.

    下面给出我分析的2个文件,一个是.h头文件,一个是.c的具体文件(我上面提到的3点可以着重看看出现的地方):


    1. /* adlist.h - A generic doubly linked list implementation
    2. *
    3. * Copyright (c) 2006-2012, Salvatore Sanfilippo <antirez at gmail dot com>
    4. * All rights reserved.
    5. *
    6. * Redistribution and use in source and binary forms, with or without
    7. * modification, are permitted provided that the following conditions are met:
    8. *
    9. *   * Redistributions of source code must retain the above copyright notice,
    10. *     this list of conditions and the following disclaimer.
    11. *   * Redistributions in binary form must reproduce the above copyright
    12. *     notice, this list of conditions and the following disclaimer in the
    13. *     documentation and/or other materials provided with the distribution.
    14. *   * Neither the name of Redis nor the names of its contributors may be used
    15. *     to endorse or promote products derived from this software without
    16. *     specific prior written permission.
    17. *
    18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28. * POSSIBILITY OF SUCH DAMAGE.
    29. */  
    30.   
    31. #ifndef __ADLIST_H__  
    32. #define __ADLIST_H__  
    33.   
    34. /* Node, List, and Iterator are the only data structures used currently. */  
    35. /* listNode结点 */  
    36. typedef struct listNode {  
    37.     //结点的前一结点  
    38.     struct listNode *prev;  
    39.     //结点的下一结点  
    40.     struct listNode *next;  
    41.     //Node的函数指针  
    42.     void *value;  
    43. } listNode;  
    44.   
    45. /* list迭代器,只能为单向 */  
    46. typedef struct listIter {  
    47.     //当前迭代位置的下一结点  
    48.     listNode *next;  
    49.     //迭代器的方向  
    50.     int direction;  
    51. } listIter;  
    52.   
    53. /* listNode 列表 */  
    54. typedef struct list {  
    55.     //列表头结点  
    56.     listNode *head;  
    57.     //列表尾结点  
    58.     listNode *tail;  
    59.       
    60.     /* 下面3个方法为所有结点公用的方法,分别在相应情况下回调用 */  
    61.     //复制函数指针  
    62.     void *(*dup)(void *ptr);  
    63.     //释放函数指针  
    64.     void (*free)(void *ptr);  
    65.     //匹配函数指针  
    66.     int (*match)(void *ptr, void *key);  
    67.     //列表长度  
    68.     unsigned long len;  
    69. } list;  
    70.   
    71. /* Functions implemented as macros */  
    72. /* 宏定义了一些基本操作 */  
    73. #define listLength(l) ((l)->len)   //获取list长度  
    74. #define listFirst(l) ((l)->head)   //获取列表首部  
    75. #define listLast(l) ((l)->tail)    //获取列表尾部  
    76. #define listPrevNode(n) ((n)->prev)  //给定结点的上一结点  
    77. #define listNextNode(n) ((n)->next)  //给定结点的下一节点  
    78. #define listNodeValue(n) ((n)->value) //给点的结点的值,这个value不是一个数值类型,而是一个函数指针  
    79.   
    80. #define listSetDupMethod(l,m) ((l)->dup = (m))  //列表的复制方法的设置  
    81. #define listSetFreeMethod(l,m) ((l)->free = (m)) //列表的释放方法的设置  
    82. #define listSetMatchMethod(l,m) ((l)->match = (m)) //列表的匹配方法的设置  
    83.   
    84. #define listGetDupMethod(l) ((l)->dup) //列表的复制方法的获取  
    85. #define listGetFree(l) ((l)->free)     //列表的释放方法的获取  
    86. #define listGetMatchMethod(l) ((l)->match) //列表的匹配方法的获取  
    87.   
    88. /* Prototypes */  
    89. /* 定义了方法的原型 */  
    90. list *listCreate(void);   //创建list列表  
    91. void listRelease(list *list);  //列表的释放  
    92. list *listAddNodeHead(list *list, void *value);  //添加列表头结点  
    93. list *listAddNodeTail(list *list, void *value);  //添加列表尾结点  
    94. list *listInsertNode(list *list, listNode *old_node, void *value, int after);  //某位置上插入及结点  
    95. void listDelNode(list *list, listNode *node);  //列表上删除给定的结点  
    96. listIter *listGetIterator(list *list, int direction);  //获取列表给定方向上的迭代器  
    97. listNode *listNext(listIter *iter);  //获取迭代器内的下一结点  
    98. void listReleaseIterator(listIter *iter);  //释放列表迭代器   
    99. list *listDup(list *orig);  //列表的复制  
    100. listNode *listSearchKey(list *list, void *key); //关键字搜索具体结点  
    101. listNode *listIndex(list *list, long index);   //下标索引具体的结点  
    102. void listRewind(list *list, listIter *li);    // 重置迭代器为方向从头开始   
    103. void listRewindTail(list *list, listIter *li); //重置迭代器为方向从尾部开始   
    104. void listRotate(list *list);  //列表旋转操作,方法名说的很玄乎,具体只能到实现里去看了  
    105.   
    106. /* Directions for iterators */  
    107. /* 定义2个迭代方向,从头部开始往尾部,第二个从尾部开始向头部 */  
    108. #define AL_START_HEAD 0  
    109. #define AL_START_TAIL 1  
    110.   
    111. #endif /* __ADLIST_H__ */  
    复制代码

    adlist.c:

    1. /* adlist.c - A generic doubly linked list implementation
    2. *
    3. * Copyright (c) 2006-2010, Salvatore Sanfilippo <antirez at gmail dot com>
    4. * All rights reserved.
    5. *
    6. * Redistribution and use in source and binary forms, with or without
    7. * modification, are permitted provided that the following conditions are met:
    8. *
    9. *   * Redistributions of source code must retain the above copyright notice,
    10. *     this list of conditions and the following disclaimer.
    11. *   * Redistributions in binary form must reproduce the above copyright
    12. *     notice, this list of conditions and the following disclaimer in the
    13. *     documentation and/or other materials provided with the distribution.
    14. *   * Neither the name of Redis nor the names of its contributors may be used
    15. *     to endorse or promote products derived from this software without
    16. *     specific prior written permission.
    17. *
    18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    22. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    28. * POSSIBILITY OF SUCH DAMAGE.
    29. */  
    30.   
    31.   
    32. #include <stdlib.h>  
    33. #include "adlist.h"  
    34. #include "zmalloc.h"  
    35.   
    36. /* Create a new list. The created list can be freed with
    37. * AlFreeList(), but private value of every node need to be freed
    38. * by the user before to call AlFreeList().
    39. *
    40. * On error, NULL is returned. Otherwise the pointer to the new list. */  
    41. /* 创建结点列表 */  
    42. list *listCreate(void)  
    43. {  
    44.     struct list *list;  
    45.   
    46.     //申请空间,如果失败了就直接返回NULL  
    47.     if ((list = zmalloc(sizeof(*list))) == NULL)  
    48.         return NULL;  
    49.     //初始化操作,头尾结点,,3个公共的函数指针全部赋值为NULL  
    50.     list->head = list->tail = NULL;  
    51.     list->len = 0;  
    52.     list->dup = NULL;  
    53.     list->free = NULL;  
    54.     list->match = NULL;  
    55.     return list;  
    56. }  
    57.   
    58. /* Free the whole list.
    59. *
    60. * This function can't fail. */  
    61. /* 释放整个列表 */  
    62. void listRelease(list *list)  
    63. {  
    64.     unsigned long len;  
    65.     listNode *current, *next;  
    66.       
    67.     //找到当前结点,也就是头结点  
    68.     current = list->head;  
    69.     len = list->len;  
    70.     while(len--) {  
    71.         //while循环依次释放结点  
    72.         next = current->next;  
    73.         //如果列表有free释放方法定义,每个结点都必须调用自己内部的value方法  
    74.         if (list->free) list->free(current->value);  
    75.         //采用redis新定义的在zfree方式释放结点,与zmalloc对应,不是free!!   
    76.         zfree(current);  
    77.         current = next;  
    78.     }  
    79.     //最后再次释放list同样是zfree  
    80.     zfree(list);  
    81. }  
    82.   
    83. /* Add a new node to the list, to head, contaning the specified 'value'
    84. * pointer as value.
    85. *
    86. * On error, NULL is returned and no operation is performed (i.e. the
    87. * list remains unaltered).
    88. * On success the 'list' pointer you pass to the function is returned. */  
    89. /* 列表添加头结点 */  
    90. list *listAddNodeHead(list *list, void *value)  
    91. {  
    92.     listNode *node;  
    93.     //定义新的listNode,并赋值函数指针  
    94.     if ((node = zmalloc(sizeof(*node))) == NULL)  
    95.         return NULL;  
    96.     node->value = value;  
    97.     if (list->len == 0) {  
    98.         //当此时没有任何结点时,头尾结点是同一个结点,前后指针为NULL  
    99.         list->head = list->tail = node;  
    100.         node->prev = node->next = NULL;  
    101.     } else {  
    102.         //设置此结点next与前头结点的位置关系  
    103.         node->prev = NULL;  
    104.         node->next = list->head;  
    105.         list->head->prev = node;  
    106.         list->head = node;  
    107.     }  
    108.       
    109.     //结点计数递增并返回  
    110.     list->len++;  
    111.     return list;  
    112. }  
    113.   
    114. /* Add a new node to the list, to tail, containing the specified 'value'
    115. * pointer as value.
    116. *
    117. * On error, NULL is returned and no operation is performed (i.e. the
    118. * list remains unaltered).
    119. * On success the 'list' pointer you pass to the function is returned. */  
    120. /* 列表添加尾结点,操作大体上与增加头结点一样,不加以描述了 */  
    121. list *listAddNodeTail(list *list, void *value)  
    122. {  
    123.     listNode *node;  
    124.   
    125.     if ((node = zmalloc(sizeof(*node))) == NULL)  
    126.         return NULL;  
    127.     node->value = value;  
    128.     if (list->len == 0) {  
    129.         list->head = list->tail = node;  
    130.         node->prev = node->next = NULL;  
    131.     } else {  
    132.         node->prev = list->tail;  
    133.         node->next = NULL;  
    134.         list->tail->next = node;  
    135.         list->tail = node;  
    136.     }  
    137.     list->len++;  
    138.     return list;  
    139. }  
    140.   
    141. /* 在old_node结点的前面或后面插入新结点 */  
    142. list *listInsertNode(list *list, listNode *old_node, void *value, int after) {  
    143.     listNode *node;  
    144.     //新申请结点,并赋值好函数指针  
    145.     if ((node = zmalloc(sizeof(*node))) == NULL)  
    146.         return NULL;  
    147.     node->value = value;  
    148.       
    149.     if (after) {  
    150.         //如果是在目标结点的后面插入的情况,将新结点的next指针指向老结点的next  
    151.         node->prev = old_node;  
    152.         node->next = old_node->next;  
    153.         if (list->tail == old_node) {  
    154.             //如果老结点已经是最后一个结点了,则新的结点直接成为尾部结点  
    155.             list->tail = node;  
    156.         }  
    157.     } else {  
    158.         //如果是在目标结点的前面插入的情况,将新结点的preview指针指向老结点的preview  
    159.         node->next = old_node;  
    160.         node->prev = old_node->prev;  
    161.         if (list->head == old_node) {  
    162.             //如果老结点已经是头结点了,则新的结点直接成为头部结点  
    163.             list->head = node;  
    164.         }  
    165.     }  
    166.     //检查Node的前后结点还有没有未连接的操作  
    167.     if (node->prev != NULL) {  
    168.         node->prev->next = node;  
    169.     }  
    170.     if (node->next != NULL) {  
    171.         node->next->prev = node;  
    172.     }  
    173.     list->len++;  
    174.     return list;  
    175. }  
    176.   
    177. /* Remove the specified node from the specified list.
    178. * It's up to the caller to free the private value of the node.
    179. *
    180. * This function can't fail. */  
    181. /* 列表删除某结点 */  
    182. void listDelNode(list *list, listNode *node)  
    183. {  
    184.     if (node->prev)  
    185.         //如果结点prev结点存在,prev的结点的下一及诶单指向Node的next结点  
    186.         node->prev->next = node->next;  
    187.     else  
    188.         //如果不存在说明是被删除的是头结点,则重新赋值Node的next为新头结点  
    189.         list->head = node->next;  
    190.      //后半操作类似  
    191.     if (node->next)  
    192.         node->next->prev = node->prev;  
    193.     else  
    194.         list->tail = node->prev;  
    195.     //同样要调用list的free函数  
    196.     if (list->free) list->free(node->value);  
    197.     zfree(node);  
    198.     list->len--;  
    199. }  
    200.   
    201. /* Returns a list iterator 'iter'. After the initialization every
    202. * call to listNext() will return the next element of the list.
    203. *
    204. * This function can't fail. */  
    205. /* 获取列表呢迭代器 */  
    206. listIter *listGetIterator(list *list, int direction)  
    207. {  
    208.     listIter *iter;  
    209.     //申请空间,失败了就直接返回NULL  
    210.     if ((iter = zmalloc(sizeof(*iter))) == NULL) return NULL;  
    211.     if (direction == AL_START_HEAD)  
    212.         //如果方向定义的是从头开始,则迭代器的next指针指向列表头结点  
    213.         iter->next = list->head;  
    214.     else  
    215.         //如果方向定义的是从尾开始,则迭代器的next指针指向列表尾结点  
    216.         iter->next = list->tail;  
    217.      //赋值好迭代器方向并返回  
    218.     iter->direction = direction;  
    219.     return iter;  
    220. }  
    221.   
    222. /* Release the iterator memory */  
    223. /* 释放迭代器内存 */  
    224. void listReleaseIterator(listIter *iter) {  
    225.     zfree(iter);  
    226. }  
    227.   
    228. /* Create an iterator in the list private iterator structure */  
    229. /* 相当于重置迭代器为方向从头开始 */  
    230. void listRewind(list *list, listIter *li) {  
    231.     li->next = list->head;  
    232.     li->direction = AL_START_HEAD;  
    233. }  
    234.   
    235. /* 重置迭代器为方向从尾部开始 */  
    236. void listRewindTail(list *list, listIter *li) {  
    237.     li->next = list->tail;  
    238.     li->direction = AL_START_TAIL;  
    239. }  
    240.   
    241. /* Return the next element of an iterator.
    242. * It's valid to remove the currently returned element using
    243. * listDelNode(), but not to remove other elements.
    244. *
    245. * The function returns a pointer to the next element of the list,
    246. * or NULL if there are no more elements, so the classical usage patter
    247. * is:
    248. *
    249. * iter = listGetIterator(list,<direction>);
    250. * while ((node = listNext(iter)) != NULL) {
    251. *     doSomethingWith(listNodeValue(node));
    252. * }
    253. *
    254. * */  
    255. /* 根据迭代器获取下一结点 */  
    256. listNode *listNext(listIter *iter)  
    257. {  
    258.     //获取当前迭代器的当前结点  
    259.     listNode *current = iter->next;  
    260.   
    261.     if (current != NULL) {  
    262.         if (iter->direction == AL_START_HEAD)  
    263.             //如果方向为从头部开始,则当前结点等于当前的结点的下一结点  
    264.             iter->next = current->next;  
    265.         else  
    266.             //如果方向为从尾部开始,则当前结点等于当前的结点的上一结点  
    267.             iter->next = current->prev;  
    268.     }  
    269.     return current;  
    270. }  
    271.   
    272. /* Duplicate the whole list. On out of memory NULL is returned.
    273. * On success a copy of the original list is returned.
    274. *
    275. * The 'Dup' method set with listSetDupMethod() function is used
    276. * to copy the node value. Otherwise the same pointer value of
    277. * the original node is used as value of the copied node.
    278. *
    279. * The original list both on success or error is never modified. */  
    280. /* 列表赋值方法,传入的参数为原始列表 */  
    281. list *listDup(list *orig)  
    282. {  
    283.     list *copy;  
    284.     listIter *iter;  
    285.     listNode *node;  
    286.   
    287.     //如果创建列表失败则直接返回  
    288.     if ((copy = listCreate()) == NULL)  
    289.         return NULL;  
    290.     //为新列表赋值好3个函数指针  
    291.     copy->dup = orig->dup;  
    292.     copy->free = orig->free;  
    293.     copy->match = orig->match;  
    294.     //获得从头方向开始的迭代器  
    295.     iter = listGetIterator(orig, AL_START_HEAD);  
    296.     while((node = listNext(iter)) != NULL) {  
    297.         //从前往后遍历结点  
    298.         void *value;  
    299.   
    300.         if (copy->dup) {  
    301.             //如果定义了列表复制方法,则调用dup方法  
    302.             value = copy->dup(node->value);  
    303.             if (value == NULL) {  
    304.                 //如果发生OOM内存溢出问题,直接释放所有空间  
    305.                 listRelease(copy);  
    306.                 listReleaseIterator(iter);  
    307.                 return NULL;  
    308.             }  
    309.         } else  
    310.             //没定义直接复制函数指针  
    311.             value = node->value;  
    312.         if (listAddNodeTail(copy, value) == NULL) {  
    313.             //后面的结点都是从尾部逐一添加结点,如果内存溢出,同上操作  
    314.             listRelease(copy);  
    315.             listReleaseIterator(iter);  
    316.             return NULL;  
    317.         }  
    318.     }  
    319.     //最后释放迭代器  
    320.     listReleaseIterator(iter);  
    321.     return copy;  
    322. }  
    323.   
    324. /* Search the list for a node matching a given key.
    325. * The match is performed using the 'match' method
    326. * set with listSetMatchMethod(). If no 'match' method
    327. * is set, the 'value' pointer of every node is directly
    328. * compared with the 'key' pointer.
    329. *
    330. * On success the first matching node pointer is returned
    331. * (search starts from head). If no matching node exists
    332. * NULL is returned. */  
    333. /* 关键字搜索Node结点此时用到了list的match方法了 */  
    334. listNode *listSearchKey(list *list, void *key)  
    335. {  
    336.     listIter *iter;  
    337.     listNode *node;  
    338.       
    339.     //获取迭代器  
    340.     iter = listGetIterator(list, AL_START_HEAD);  
    341.     while((node = listNext(iter)) != NULL) {  
    342.         //遍历循环  
    343.         if (list->match) {  
    344.             //如果定义了list的match方法,则调用match方法  
    345.             if (list->match(node->value, key)) {  
    346.                 //如果方法返回true,则代表找到结点,释放迭代器  
    347.                 listReleaseIterator(iter);  
    348.                 return node;  
    349.             }  
    350.         } else {  
    351.             //如果没有定义list 的match方法,则直接比较函数指针  
    352.             if (key == node->value) {  
    353.                 //如果相等,则代表找到结点,释放迭代器  
    354.                 listReleaseIterator(iter);  
    355.                 return node;  
    356.             }  
    357.         }  
    358.     }  
    359.     listReleaseIterator(iter);  
    360.     return NULL;  
    361. }  
    362.   
    363. /* Return the element at the specified zero-based index
    364. * where 0 is the head, 1 is the element next to head
    365. * and so on. Negative integers are used in order to count
    366. * from the tail, -1 is the last element, -2 the penultimate
    367. * and so on. If the index is out of range NULL is returned. */  
    368. /* 根据下标值返回相应的结点*/  
    369. /*下标有2种表示形式,从头往后一次0, 1, 2,...从后往前是 ...-3, -2, -1.-1为最后一个结点*/  
    370. listNode *listIndex(list *list, long index) {  
    371.     listNode *n;  
    372.   
    373.     if (index < 0) {  
    374.         //如果index为负数,则从后往前数  
    375.         index = (-index)-1;  
    376.         n = list->tail;  
    377.         while(index-- && n) n = n->prev;  
    378.     } else {  
    379.         //如果index为正数,则从前往后数  
    380.         n = list->head;  
    381.         while(index-- && n) n = n->next;  
    382.     }  
    383.     return n;  
    384. }  
    385.   
    386. /* Rotate the list removing the tail node and inserting it to the head. */  
    387. /* rotate操作其实就是把尾部结点挪到头部,原本倒数第二个结点变为尾部结点 */  
    388. void listRotate(list *list) {  
    389.     listNode *tail = list->tail;  
    390.   
    391.     //如果长度为不足,直接返回,之前宏定义的方法  
    392.     if (listLength(list) <= 1) return;  
    393.   
    394.     /* Detach current tail */  
    395.     //替换新的尾部结点,原结点后挪一个位置  
    396.     list->tail = tail->prev;  
    397.     list->tail->next = NULL;  
    398.       
    399.     /* Move it as head */  
    400.     //设置新结点  
    401.     list->head->prev = tail;  
    402.     tail->prev = NULL;  
    403.     tail->next = list->head;  
    404.     list->head = tail;  
    405. }  
    复制代码

    其实目前网上的各种的解析都有吧,每个人阅读带给自己的感受是不一样的,只有自己亲手体验过才叫真的体会过,阅读代码的确会给人很多启发,非常严谨吧,每行代码,抱着一种学习,欣赏的心态看待代码。不错,良好的开始,继续坚持。


    转自:http://blog.csdn.net/androidlushangderen/article/details/39833893


    上一篇:Redis源码分析(一)--Redis结构解析
    下一篇:Redis源码分析(三)---dict哈希结构
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    阿里云
    阿里云

    Archiver|手机版|小黑屋|Redis中国用户组 ( 京ICP备15003959号

    GMT+8, 2017-11-21 17:46 , Processed in 0.110103 second(s), 33 queries .

    Powered by Discuz! X3.2

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表