LINUX常用数据结构

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/*

* List definitions.

*/

#define LIST_HEAD(name, type) \

struct name { \

struct type *lh_first; /* first element */ \

}

#define LIST_ENTRY(type) \

struct { \

struct type *le_next; /* next element */ \

struct type **le_prev; /* address of previous next element */ \ }

/*

* List functions.

*/

#define LIST_INIT(head) { \

(head)->lh_first = NULL; \

}

#define LIST_INSERT_AFTER(listelm, elm, field) { \

if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ (listelm)->field.le_next->field.le_prev = \

&(elm)->field.le_next; \

(listelm)->field.le_next = (elm); \

(elm)->field.le_prev = &(listelm)->field.le_next; \

}

#define LIST_INSERT_HEAD(head, elm, field) { \

if (((elm)->field.le_next = (head)->lh_first) != NULL) \

(head)->lh_first->field.le_prev = &(elm)->field.le_next;\

(head)->lh_first = (elm); \

(elm)->field.le_prev = &(head)->lh_first; \

}

#define LIST_REMOVE(elm, field) { \

if ((elm)->field.le_next != NULL) \

(elm)->field.le_next->field.le_prev = \

(elm)->field.le_prev; \

*(elm)->field.le_prev = (elm)->field.le_next; \

}

/*

* Tail queue definitions.

*/

#define TAILQ_HEAD(name, type) \

struct name { \

struct type *tqh_first; /* first element */ \

struct type **tqh_last; /* addr of last next element */ \

}

#define TAILQ_ENTRY(type) \

struct { \

struct type *tqe_next; /* next element */ \

struct type **tqe_prev; /* address of previous next element */ \ }

/*

* Tail queue functions.

*/

#define TAILQ_INIT(head) { \

(head)->tqh_first = NULL; \

(head)->tqh_last = &(head)->tqh_first; \

}

#define TAILQ_INSERT_HEAD(head, elm, field) { \

if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \

(elm)->field.tqe_next->field.tqe_prev = \

&(elm)->field.tqe_next; \

else \

(head)->tqh_last = &(elm)->field.tqe_next; \

(head)->tqh_first = (elm); \

(elm)->field.tqe_prev = &(head)->tqh_first; \

}

#define TAILQ_INSERT_TAIL(head, elm, field) { \

(elm)->field.tqe_next = NULL; \

(elm)->field.tqe_prev = (head)->tqh_last; \

*(head)->tqh_last = (elm); \

(head)->tqh_last = &(elm)->field.tqe_next; \

}

#define TAILQ_INSERT_AFTER(head, listelm, elm, field) { \

if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ (elm)->field.tqe_next->field.tqe_prev = \

&(elm)->field.tqe_next; \

else \

(head)->tqh_last = &(elm)->field.tqe_next; \

(listelm)->field.tqe_next = (elm); \

(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \

}

相关文档
最新文档