zoukankan      html  css  js  c++  java
  • Redis实现原理(1)--链表

    链表是Redis中使用非常广泛的一种数据结构,很多地方如List结构底层就是用链表实现的。

    链表的定义在头文件adlist.h 中,很常见的双向链表,结构如下:

     1 // 链表节点
     2 typedef struct listNode {
     3     struct listNode *prev; //指向前一个节点
     4     struct listNode *next; //指向后一个节点
     5     void *value; //值域
     6 } listNode; 
     7 // 链表遍历迭代指针
     8 typedef struct listIter {
     9     listNode *next; //下一节点指针
    10     int direction; // 方向
    11 } listIter;
    12 
    13 // 链表结构
    14 typedef struct list {
    15     listNode *head; //链表头指针
    16     listNode *tail; //链表尾指针
    17     void *(*dup)(void *ptr); //节点值域复制函数指针
    18     void (*free)(void *ptr); //节点值域释放函数指针
    19     int (*match)(void *ptr, void *key); //节点值域比较函数指针
    20     unsigned long len; //链表长度
    21 } list;
  • 相关阅读:
    Balanced Binary Tree
    Minimum Depth of Binary Tree
    Path Sum
    Flatten Binary Tree to Linked List
    Distinct Subsequences
    Chp3: Stacks and Queue
    Chp2: Linked List
    Populating Next Right Pointers in Each Node
    Valid Palindrome
    Binary Tree Maximum Path Sum
  • 原文地址:https://www.cnblogs.com/yancey/p/3887830.html
Copyright © 2011-2022 走看看