List from Linux by DGOD

xiaoxiao2021-03-06  93

/ ************************************************** ******** Something Simplified from Linux Source Code. This Workis Done by DGOD. Use this List functions, You Should Support C99 OR . To Use this, IF Your Compiler Don't Support, Rewrite the new parameter n, else you shull, n, else you shull, n, else you shull, n, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ************************************************* /

#ifndef _list_h_ # define _list_h_

Typedef struct node {struct node * prev, * next;} node, * pnode

#define offsetof ((int) & ((type *) 0) -> MEMBER) #define list_entry (PTR, TYPE, MEMBER) (/ (Type *) / ((char *) (PTR) ) -offsetof (Type, Member)) /)

Static inline void list_init (pnode n) {n-> prev = n-> next = n;}

Static inline void __list_add (pnode n, pnode prev, pnode next) {next-> prev = n; prev-> next = n; n-> next = next; n-> prev = prev;}

Static inline void list_add (pnode n, pnode head) {__LIST_ADD (n, head, head-> next);}

Static inline void list_add_tail (pnode n, pnode head) {__list_add (n, head-> prev, head);}

Static inline void __list_del (pnode prev, pnode next) {prev-> next = next; Next-> prev = prev;}

Static inline void list_del (pnode n) {__list_del (n-> prev, n-> next); list_init (n);}

Static inline void list_move (pnode n, pnode head) {__list_del (n-> prev, n-> next); list_add (n, head);}

Static inline void list_move_tail (pnode n, pnode head) {__list_del (n-> prev, n-> next); list_add_tail (n, head);}

Static inline int list_empty (pnode head) {return head == head-> next;

Static inline void __list_splice (pnode list, pnode head) {node * first = list-> next; node * last = list-> prev; node * at = head-> next; first-> prev = head; head-> next = first;

Last-> next = at; at-> prev = last;}

Static Inline void list_splice (pnode list, pnode head) {i (! list_empty (list)) {__list_splice (list, head); list_init (list);}}

#define foreach / for (node ​​* n = pOS = (head) -> next; n = n-> next, pos! = (head); POS = n)

#ENDIF / / _ LIST_H_

转载请注明原文地址:https://www.9cbs.com/read-123196.html

New Post(0)