VC下勉強可用的list

linux內核中的list太好用了,可惜VC編譯器不支持 typeof?關鍵字,將linux內核中的list直接移植過來不能用

修改所有與typeof相關的代碼后,終于可以勉強在VC下運行起來了,但是還不完美,list_for_each_entry和list_for_each_entry_safe需要增加一個參數表示變量的類型

修改后的代碼如下

#ifndef __EKWIN__LIST__H__
#define __EKWIN__LIST__H__#define LIST_POISON1  ((struct list_head *) 0)
#define LIST_POISON2  ((struct list_head *) 0)
#define HLIST_POISON1  ((struct hlist_node *) 0)
#define HLIST_POISON2  ((struct hlist_node **) 0)#define prefetch(x) (x)
#define likely(x)    (x)
#define unlikely(x)    (x)
#define container_of(ptr, type, member) \(type *)( (char *)ptr - offsetof(type,member) )/** Simple doubly linked list implementation.** Some of the internal functions ("__xxx") are useful when* manipulating whole lists rather than single entries, as* sometimes we already know the next/prev entries and we can* generate better code by using them directly rather than* using the generic single-entry routines.*/struct list_head {struct list_head *next, *prev;
};#define LIST_HEAD_INIT(name) { &(name), &(name) }#define LIST_HEAD(name) \struct list_head name = LIST_HEAD_INIT(name)static inline void INIT_LIST_HEAD(struct list_head *list)
{list->next = list;list->prev = list;
}static inline void __list_add(struct list_head *node,struct list_head *prev,struct list_head *next)
{next->prev = node;node->next = next;node->prev = prev;prev->next = node;
}/*** list_add - add a new entry* @new: new entry to be added* @head: list head to add it after** Insert a new entry after the specified head.* This is good for implementing stacks.*/
static inline void list_add(struct list_head *node, struct list_head *head)
{__list_add(node, head, head->next);
}/*** list_add_tail - add a new entry* @new: new entry to be added* @head: list head to add it before** Insert a new entry before the specified head.* This is useful for implementing queues.*/
static inline void list_add_tail(struct list_head *node, struct list_head *head)
{__list_add(node, head->prev, head);
}/** Delete a list entry by making the prev/next entries* point to each other.** This is only for internal list manipulation where we know* the prev/next entries already!*/
static inline void __list_del(struct list_head * prev, struct list_head * next)
{next->prev = prev;prev->next = next;
}/*** list_del - deletes entry from list.* @entry: the element to delete from the list.* Note: list_empty() on entry does not return true after this, the entry is* in an undefined state.*/
static inline void list_del(struct list_head *entry)
{__list_del(entry->prev, entry->next);entry->next = LIST_POISON1;entry->prev = LIST_POISON2;
}/*** list_replace - replace old entry by new one* @old : the element to be replaced* @new : the new element to insert** If @old was empty, it will be overwritten.*/
static inline void list_replace(struct list_head *old,struct list_head *node)
{node->next = old->next;node->next->prev = node;node->prev = old->prev;node->prev->next = node;
}static inline void list_replace_init(struct list_head *old,struct list_head *node)
{list_replace(old, node);INIT_LIST_HEAD(old);
}/*** list_del_init - deletes entry from list and reinitialize it.* @entry: the element to delete from the list.*/
static inline void list_del_init(struct list_head *entry)
{__list_del(entry->prev, entry->next);INIT_LIST_HEAD(entry);
}/*** list_move - delete from one list and add as another's head* @list: the entry to move* @head: the head that will precede our entry*/
static inline void list_move(struct list_head *list, struct list_head *head)
{__list_del(list->prev, list->next);list_add(list, head);
}/*** list_move_tail - delete from one list and add as another's tail* @list: the entry to move* @head: the head that will follow our entry*/
static inline void list_move_tail(struct list_head *list,struct list_head *head)
{__list_del(list->prev, list->next);list_add_tail(list, head);
}/*** list_is_last - tests whether @list is the last entry in list @head* @list: the entry to test* @head: the head of the list*/
static inline int list_is_last(const struct list_head *list,const struct list_head *head)
{return list->next == head;
}
static inline int list_is_first(const struct list_head *list,const struct list_head *head)
{return list->prev == head;
}/*** list_empty - tests whether a list is empty* @head: the list to test.*/
static inline int list_empty(const struct list_head *head)
{return head->next == head;
}/*** list_empty_careful - tests whether a list is empty and not being modified* @head: the list to test** Description:* tests whether a list is empty _and_ checks that no other CPU might be* in the process of modifying either member (next or prev)** NOTE: using list_empty_careful() without synchronization* can only be safe if the only activity that can happen* to the list entry is list_del_init(). Eg. it cannot be used* if another CPU could re-list_add() it.*/
static inline int list_empty_careful(const struct list_head *head)
{struct list_head *next = head->next;return (next == head) && (next == head->prev);
}/*** list_is_singular - tests whether a list has just one entry.* @head: the list to test.*/
static inline int list_is_singular(const struct list_head *head)
{return !list_empty(head) && (head->next == head->prev);
}static inline void __list_cut_position(struct list_head *list,struct list_head *head, struct list_head *entry)
{struct list_head *new_first = entry->next;list->next = head->next;list->next->prev = list;list->prev = entry;entry->next = list;head->next = new_first;new_first->prev = head;
}/*** list_cut_position - cut a list into two* @list: a new list to add all removed entries* @head: a list with entries* @entry: an entry within head, could be the head itself*    and if so we won't cut the list** This helper moves the initial part of @head, up to and* including @entry, from @head to @list. You should* pass on @entry an element you know is on @head. @list* should be an empty list or a list you do not care about* losing its data.**/
static inline void list_cut_position(struct list_head *list,struct list_head *head, struct list_head *entry)
{if (list_empty(head))return;if (list_is_singular(head) &&(head->next != entry && head != entry))return;if (entry == head)INIT_LIST_HEAD(list);else__list_cut_position(list, head, entry);
}static inline void __list_splice(const struct list_head *list,struct list_head *prev,struct list_head *next)
{struct list_head *first = list->next;struct list_head *last = list->prev;first->prev = prev;prev->next = first;last->next = next;next->prev = last;
}/*** list_splice - join two lists, this is designed for stacks* @list: the new list to add.* @head: the place to add it in the first list.*/
static inline void list_splice(const struct list_head *list,struct list_head *head)
{if (!list_empty(list))__list_splice(list, head, head->next);
}/*** list_splice_tail - join two lists, each list being a queue* @list: the new list to add.* @head: the place to add it in the first list.*/
static inline void list_splice_tail(struct list_head *list,struct list_head *head)
{if (!list_empty(list))__list_splice(list, head->prev, head);
}/*** list_splice_init - join two lists and reinitialise the emptied list.* @list: the new list to add.* @head: the place to add it in the first list.** The list at @list is reinitialised*/
static inline void list_splice_init(struct list_head *list,struct list_head *head)
{if (!list_empty(list)) {__list_splice(list, head, head->next);INIT_LIST_HEAD(list);}
}/*** list_splice_tail_init - join two lists and reinitialise the emptied list* @list: the new list to add.* @head: the place to add it in the first list.** Each of the lists is a queue.* The list at @list is reinitialised*/
static inline void list_splice_tail_init(struct list_head *list,struct list_head *head)
{if (!list_empty(list)) {__list_splice(list, head->prev, head);INIT_LIST_HEAD(list);}
}/*** list_entry - get the struct for this entry* @ptr:    the &struct list_head pointer.* @type:    the type of the struct this is embedded in.* @member:    the name of the list_struct within the struct.*/
#define list_entry(ptr, type, member) \container_of(ptr, type, member)/*** list_first_entry - get the first element from a list* @ptr:    the list head to take the element from.* @type:    the type of the struct this is embedded in.* @member:    the name of the list_struct within the struct.** Note, that list is expected to be not empty.*/
#define list_first_entry(ptr, type, member) \list_entry((ptr)->next, type, member)
#define list_last_entry(ptr, type, member) \list_entry((ptr)->prev, type, member)/*** list_for_each    -    iterate over a list* @pos:    the &struct list_head to use as a loop cursor.* @head:    the head for your list.*/
#define list_for_each(pos, head) \for (pos = (head)->next; prefetch(pos->next), pos != (head); \pos = pos->next)/*** __list_for_each    -    iterate over a list* @pos:    the &struct list_head to use as a loop cursor.* @head:    the head for your list.** This variant differs from list_for_each() in that it's the* simplest possible list iteration code, no prefetching is done.* Use this for code that knows the list to be very short (empty* or 1 entry) most of the time.*/
#define __list_for_each(pos, head) \for (pos = (head)->next; pos != (head); pos = pos->next)/*** list_for_each_prev    -    iterate over a list backwards* @pos:    the &struct list_head to use as a loop cursor.* @head:    the head for your list.*/
#define list_for_each_prev(pos, head) \for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \pos = pos->prev)/*** list_for_each_safe - iterate over a list safe against removal of list entry* @pos:    the &struct list_head to use as a loop cursor.* @n:        another &struct list_head to use as temporary storage* @head:    the head for your list.*/
#define list_for_each_safe(pos, n, head) \for (pos = (head)->next, n = pos->next; pos != (head); \pos = n, n = pos->next)/*** list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry* @pos:    the &struct list_head to use as a loop cursor.* @n:        another &struct list_head to use as temporary storage* @head:    the head for your list.*/
#define list_for_each_prev_safe(pos, n, head) \for (pos = (head)->prev, n = pos->prev; \prefetch(pos->prev), pos != (head); \pos = n, n = pos->prev)/*** list_for_each_entry    -    iterate over list of given type* @pos:    the type * to use as a loop cursor.* @head:    the head for your list.* @member:    the name of the list_struct within the struct.*/
#define list_for_each_entry(postp, pos, head, member)                \for (pos = list_entry((head)->next, postp, member);    \prefetch(pos->member.next), &pos->member != (head);     \pos = list_entry(pos->member.next, postp, member))/*** list_for_each_entry_safe - iterate over list of given type safe against removal of list entry* @pos:    the type * to use as a loop cursor.* @n:        another type * to use as temporary storage* @head:    the head for your list.* @member:    the name of the list_struct within the struct.*/
#define list_for_each_entry_safe(postp, pos, n, head, member)            \for (pos = list_entry((head)->next, postp, member),    \n = list_entry(pos->member.next, postp, member);    \&pos->member != (head);                     \pos = n, n = list_entry(n->member.next, postp, member))/** Double linked lists with a single pointer list head.* Mostly useful for hash tables where the two pointer list head is* too wasteful.* You lose the ability to access the tail in O(1).*/struct hlist_head {struct hlist_node *first;
};struct hlist_node {struct hlist_node *next, **pprev;
};#define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
static inline void INIT_HLIST_NODE(struct hlist_node *h)
{h->next = NULL;h->pprev = NULL;
}static inline int hlist_unhashed(const struct hlist_node *h)
{return !h->pprev;
}static inline int hlist_empty(const struct hlist_head *h)
{return !h->first;
}static inline void __hlist_del(struct hlist_node *n)
{struct hlist_node *next = n->next;struct hlist_node **pprev = n->pprev;*pprev = next;if (next)next->pprev = pprev;
}static inline void hlist_del(struct hlist_node *n)
{__hlist_del(n);n->next = HLIST_POISON1;n->pprev = HLIST_POISON2;
}static inline void hlist_del_init(struct hlist_node *n)
{if (!hlist_unhashed(n)) {__hlist_del(n);INIT_HLIST_NODE(n);}
}static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
{struct hlist_node *first = h->first;n->next = first;if (first)first->pprev = &n->next;h->first = n;n->pprev = &h->first;
}/* next must be != NULL */
static inline void hlist_add_before(struct hlist_node *n,struct hlist_node *next)
{n->pprev = next->pprev;n->next = next;next->pprev = &n->next;*(n->pprev) = n;
}static inline void hlist_add_after(struct hlist_node *n,struct hlist_node *next)
{next->next = n->next;n->next = next;next->pprev = &n->next;if(next->next)next->next->pprev  = &next->next;
}/** Move a list from one list head to another. Fixup the pprev* reference of the first entry if it exists.*/
static inline void hlist_move_list(struct hlist_head *old,struct hlist_head *node)
{node->first = old->first;if (node->first)node->first->pprev = &node->first;old->first = NULL;
}#define hlist_entry(ptr, type, member) container_of(ptr,type,member)#define hlist_for_each(pos, head) \for (pos = (head)->first; pos; \pos = pos->next)#define hlist_for_each_safe(pos, n, head) \for (pos = (head)->first; pos; \pos = n)/*** hlist_for_each_entry    - iterate over list of given type* @tpos:    the type * to use as a loop cursor.* @pos:    the &struct hlist_node to use as a loop cursor.* @head:    the head for your list.* @member:    the name of the hlist_node within the struct.*/
#define hlist_for_each_entry(tpos, pos, head, member)             \for (pos = (head)->first;                     \pos && ({ prefetch(pos->next); 1;}) &&             \({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \pos = pos->next)/*** hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry* @tpos:    the type * to use as a loop cursor.* @pos:    the &struct hlist_node to use as a loop cursor.* @n:        another &struct hlist_node to use as temporary storage* @head:    the head for your list.* @member:    the name of the hlist_node within the struct.*/
#define hlist_for_each_entry_safe(tpos, pos, n, head, member)          \for (pos = (head)->first;                     \pos && ({ n = pos->next; 1; }) &&                  \({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \pos = n)#define list_next(ptr) \((ptr)->member.next)
#define list_prev(ptr, member) \((ptr)->member.prev)static inline int list_count(struct list_head *head)
{int count = 0;struct list_head *pos;list_for_each(pos, head) {count++;}return count;
}/* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
#define GOLDEN_RATIO_PRIME_32 0x9e370001UL
#define GOLDEN_RATIO_PRIME GOLDEN_RATIO_PRIME_32
#define hash_long(val, bits) hash_32(val, bits)static inline unsigned int hash_32(unsigned int val, unsigned int bits)
{/* On some cpus multiply is faster, on others gcc will do shifts */unsigned int hash = val * GOLDEN_RATIO_PRIME_32;/* High bits are more random, so use them. */return hash >> (32 - bits);
}static inline unsigned long hash_ptr(void *ptr, unsigned int bits)
{return hash_long((unsigned long)ptr, bits);
}#endif // __EKWIN__LIST__H__

?

轉載于:https://www.cnblogs.com/cppboy/p/3717632.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/375904.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/375904.shtml
英文地址,請注明出處:http://en.pswp.cn/news/375904.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

當執行游戲0xc000007b錯誤的解決方法

如圖,這個錯誤使無數玩家煩惱。 出現這個錯誤,可能是硬件的問題,也可能是軟件的問題。可是,因為硬件引起該問題的概率非常小,而且除了更換硬件之外沒有更好的解決方法,因此本文將具體介紹怎樣通過軟件解決此…

android觸屏音文件地址,Android音視頻-音頻采集

Android的音視頻開發是我暫定的一個職業發展的一個方向,通過自學記錄一些記了又忘記的知識。音頻基礎知識采樣率(samplerate)藍色代表模擬音頻信號,紅色的點代表采樣得到的量化數值。采用就是把模擬信號數字化的過程,不僅僅是音頻需要采樣&am…

平衡二叉樹,AVL樹之圖解篇

學習過了二叉查找樹,想必大家有遇到一個問題。例如,將一個數組{1,2,3,4}依次插入樹的時候,形成了圖1的情況。有建立樹與沒建立樹對于數據的增刪查改已經沒有了任何幫助,反而增添了維護的成本。而只有建立的樹如圖2,才能…

窗體

GDI:圖形設備接口 所有能夠將電子信號轉換成圖像顯示的設備是圖形設備, 常見的圖形設備有顯示器,打印機。 Winform封裝了GDI底層的接口,提供一組面向對象的接口,供我們使用 Partial關鍵字,用他修飾的類叫分布類/部分類…

android程序到處apk,導出已安裝到手機中程序的apk文件

查看該手機所有安裝包的包名,輸入adb shell pm list packages找到你要導出的包名獲取該安裝apk的路徑,輸入adb shell pm path com.pfoc.myacurite得到包所在路徑:導出文件,adb pull /data/app/com.pfoc.myacurite-1/base.apk /Use…

數據結構--順序棧

棧&#xff1a;限定僅在表尾進行插入或刪除操作的線性表&#xff0c;對棧來說&#xff0c;表尾端為棧頂&#xff0c;表頭端為棧底。 本文實現了順序棧的表示和相關函數操作&#xff0c;以及一些驗證性代碼。 #include<stdio.h> #include<stdlib.h> #include<w…

Mysql 的一些基本用法

一、增加字段 alter table students add IsImportJcxx int set default 0 COMMENT 是否導入基礎信息平臺 1 是導入; 二、刪除字段 alter table provincestudentinfo drop column NativePlace; 三、創建表 CREATE TABLE 表名 ( IconId int not null auto_increment, 字段名 …

Python 文件的輸入與輸出

1. 文本文件的讀寫主要通過open()所構建的文件對象來實現。我們打開一個文件&#xff0c;并使用一個對象來表示該文件 , f open(d&#xff0c;r) 其中d是文件名&#xff0c;r是模式 "r" 文件只讀,使用 f.write()會報錯 "w" 用于寫入&#xff0c;每次使用f…

查詢表的內容

1&#xff1a;as給表另外命名 2&#xff1a;desc倒序 3&#xff1a;order by分組 4&#xff1a;select*form表名where條件轉載于:https://www.cnblogs.com/chen1101465910/p/3719944.html

人之為生也&#xff0c;凡不破者亦難立之。縱所思之&#xff0c;生而順之者&#xff0c;亦難成也。然吾之路也&#xff0c;亦難行之&#xff0c;至此二十有余&#xff0c;雖無半百之所歷&#xff0c;亦無順途&#xff0c;每及思之&#xff0c;慨之多也。 偶有所感&#xff0c;念…

Delphi 一些函數解釋

AdjustWindowRect 給定一種窗口樣式&#xff0c;計算獲得目標客戶區矩形所需的窗口大小 AnyPopup 判斷屏幕上是否存在任何彈出式窗口 ArrangeIconicWindows 排列一個父窗口的最小化子窗口 AttachThreadInput 連接線程輸入函數 BeginDeferWindowPos 啟動構建一系列新窗口位置的過…

盒子模型的總結

轉載于:https://www.cnblogs.com/zy2012/p/3725677.html

ubuntu node.js Binaries方式安裝(二進制文件安裝)

node.js在windows下有安裝文件&#xff0c;直接一路下一步就可以了&#xff0c;但大家都知道在windows下用node.js總會遇到一些問題&#xff0c;所以就會用到linux。 看到網上幾乎是在linux下編譯安裝node.js。感覺很奇怪&#xff0c;其實官網直接有 node.js linux binaries文…

maven generating project in batch mode hang

現象&#xff1a; 執行 archetype:generate 的時候&#xff0c;會產生[INFO] Generating project in Batch mode原因是&#xff1a;網速問題&#xff0c; 解決方法&#xff1a; 設置maven不要從遠程服務器上獲取catalog&#xff0c;增加參數-DarchetypeCataloginternal 如何在i…

android手機生成pdf格式文件,Android根據pdf模板生成pdf文件

1 public voidFillPdfTemplate(String id) {2 android.icu.text.SimpleDateFormat simpleDateFormat 3 new android.icu.text.SimpleDateFormat("HHmmss");//HH:mm:ss4 //設置默認時區5 simpleDateFormat.setTimeZone(android.icu.util.TimeZone.getTimeZone("G…

棧的應用--數制轉換

十進制N和其他d進制 N(N div d)XdN mod d &#xff08;其中&#xff1a;div為整除運算&#xff0c;mod為求余運算&#xff09; void conversion(){SqStack S;int N;SElemType e;Init_Stack(S);scanf("%d",&N);while(N){Push(S,N%8);NN/8;}while(!Stack_Empty(S…

radio按鈕點擊文字選中按鈕

<input type"radio" name"name" id"rd" value" " /><label for"rd">測試</label> 轉載于:https://www.cnblogs.com/kevin1988/p/3727041.html

tokumx經營報表

#見數據庫列表 show dbs#切換/創建數據庫(當創建一個集合(table)的時候會自己主動創建當前數據庫)use admin;#添加用戶 db.addUser("zhoulf ","123456",true)#更改password&#xff08;為已經存在的用戶更改password&#xff09; db.addUser("zhoulf …

微博 Android 啟動廣告,使用Xposed去除微博國際版的啟動廣告

本文同步更新于旺仔的個人博客&#xff0c;訪問可能有點慢&#xff0c;多刷新幾次。前面有篇文章已經介紹了如何創建Xposed模塊的文章了&#xff0c;這篇就讓我們來實現一個簡單的去除啟動廣告的功能吧。起因為什么要是要去掉微博國際版的開屏廣告呢&#xff0c;因為廣告煩人啊…

鴿巢原理

鴿巢原理&#xff1a; n1個鴿子放入n個窩中&#xff0c;至少有一個窩含有兩只鴿子 Find a multipleTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5590 Accepted: 2434 Special JudgeDescription The input contains N natural (i.e. positive integer) numbers…