list from linux by dgod

转载 2004年08月26日 17:59:00

/*********************************************************
    Something simplified from linux source code. this work
is done by dgod.
    Use this list functions, you should support c99 or ++.
To use this, include this file.
 If your compiler don't support, rewrite the micro of
foreach, if just no change to the list move the new
parameter n, else you shuld have n to define outside the
for loop and give the foreach more param
**********************************************************/

#ifndef _LIST_H_
#define _LIST_H_

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

#define offsetof(type,member) ((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)
{
    if(!list_empty(list))
    {
     __list_splice(list,head);
     list_init(list);
    }   
}

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

#endif //_LIST_H_

Ubuntu读取windows下的共享文件夹 Unable to mount location Failed to retrieve share list from server

解决方法: Ubuntu中修改/etc/hosts 添加一列数据:windows的主机IP地址 + windows的主机名称 即可解决。 原文链接: http://www.ubunt...
  • yangzhen_0512
  • yangzhen_0512
  • 2017-03-01 16:45:49
  • 876

Select From List 下拉列表框定位

以下是我整理了最近用到的2个关键字:(后续用上其他几个,再陆续补充上来) Select From List By Value的用法: Name:  Select From List By Va...
  • hapasm
  • hapasm
  • 2016-12-12 15:52:57
  • 1587

Type safety: Unchecked cast from List to List<Book>

 处理MyEclipse中泛型转换的警告 之 隐藏方法
  • u013532827
  • u013532827
  • 2014-05-02 10:53:26
  • 2297

使用数组时注意的一些问题

/*  *数组注意的一些问题  */ #include using namespace std; int main() {  const int ArraySize = 5;  //...
  • zhuo_wang
  • zhuo_wang
  • 2012-09-28 18:08:50
  • 3678

list=(List)session.createQuery("from Students").list();

list=(List)session.createQuery("from Students").list(); 即使表中数据为空,list也不是null值,而是“[]”!所以不能根据list的返回值...
  • zhujiaxing666666
  • zhujiaxing666666
  • 2013-01-11 20:43:54
  • 2052

Java - Warning: Unchecked cast from object to array list

Warning: Unchecked cast from object to array list本文地址:http://blog.csdn.net/caroline_wendy警告发生在对象(Obj...
  • u012515223
  • u012515223
  • 2015-02-07 23:22:11
  • 3646

LeetCode(83)Remove Duplicates from Sorted List

题目如下: Given a sorted linked list, delete all duplicates such that each element appear only once. For...
  • feliciafay
  • feliciafay
  • 2014-01-10 08:06:49
  • 2870

Remove Duplicates from Sorted List -- LeetCode

原题链接: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list/  这是一道比较简单的链表操作的题目,要求是删去有序...
  • linhuanmars
  • linhuanmars
  • 2014-04-23 11:25:06
  • 8932

Remove Duplicates from Sorted List II -- LeetCode

原题链接: http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/  这道题跟Remove Duplicates...
  • linhuanmars
  • linhuanmars
  • 2014-04-24 08:33:10
  • 10838

APP上传时卡在Fetching list of teams from。。。

这种情况是xcode出了问题,或者网络,重启网络,关掉xcode重新打开就好了
  • iOSTerry
  • iOSTerry
  • 2016-11-26 00:16:47
  • 3538
收藏助手
不良信息举报
您举报文章:list from linux by dgod
举报原因:
原因补充:

(最多只允许输入30个字)