zoukankan      html  css  js  c++  java
  • Linux下链表常用实现方式

    struct _inode_table {
            pthread_mutex_t lock;
            size_t hashsize; 
            char *name; 
            struct list_head lru; 
            size_t lru_size;
    };
    struct _inode {
            inode_table_t *table; 
            uuid_t gfid;
            gf_lock_t lock;
            struct list_head list;
    };

    struct list_head {
        struct list_head *next;
        struct list_head *prev;
    };

      
    //初始化,头和尾都指向自己
    #define INIT_LIST_HEAD(head) do {            \
            (head)->next = (head)->prev = head;    \
        } while (0)
    //添加到双向列表
    static inline void list_add (struct list_head *new, struct list_head *head)
    {
        new->prev = head;
        new->next = head->next;
        new->prev->next = new;
        new->next->prev = new;
    }
    //初始化函数
    _inode_table_t*
     inode_table_new {
     inode_table_t *new = (void *)GF_CALLOC(1, sizeof (*new), gf_common_mt_inode_table_t);
     INIT_LIST_HEAD (&new->lru);
    }
    //初始化函数,
    inode_t *
    inode_new (inode_table_t *table)
    {
    inode_t *newi = NULL;
    newi->table = table;
    INIT_LIST_HEAD (&newi->list);
    list_add (&newi->list, &table->lru);
    table->lru_size++;
    }
    每生产一个inode,inode自己维护inode->list,并把inode->list添加到table->lru里面去,由table维护整个inode列表。

    使用:
  • 相关阅读:
    773. 有效的字母异位词
    768. 杨辉三角
    759. 时间角度
    757. 最短无序数组
    749. 约翰的后花园
    737. 查找矩阵
    AIX如何点亮HBA卡
    Spring Boot 静态文件,请求不到,util文件夹
    Spring Boot 静态文件,请求不到,util文件夹
    Bootstrap表格组件 Bootstrap Table
  • 原文地址:https://www.cnblogs.com/mingziday/p/2360546.html
Copyright © 2011-2022 走看看