| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /*
- * category: [data structure]
- * apply status:
- * edit status:
- * build status:
- * description:
- */
- #ifndef LISTENTRY_H
- #define LISTENTRY_H
- #pragma once
- static __inline void ListEntry_InitNode(PLIST_ENTRY node)
- {
- node->Flink = node->Blink = NULL;
- }
- static __inline void ListEntry_InitHead(PLIST_ENTRY head)
- {
- head->Blink = head;
- head->Flink = head;
- }
- static __inline void ListEntry_DeleteNode(PLIST_ENTRY node)
- {
- PLIST_ENTRY prev = node->Blink;
- PLIST_ENTRY next = node->Flink;
- prev->Flink = next;
- next->Blink = prev;
- node->Flink = node->Blink = NULL;
- }
- static __inline void ListEntry_Insert(PLIST_ENTRY prev, PLIST_ENTRY next, PLIST_ENTRY node)
- {
- prev->Flink = node;
- node->Blink = prev;
- node->Flink = next;
- next->Blink = node;
- }
- static __inline void ListEntry_InsertBefore(PLIST_ENTRY pos, PLIST_ENTRY node)
- {
- ListEntry_Insert(pos->Blink, pos, node);
- }
- static __inline void ListEntry_InsertAfter(PLIST_ENTRY pos, PLIST_ENTRY node)
- {
- ListEntry_Insert(pos, pos->Flink, node);
- }
- static __inline void ListEntry_AddTail(PLIST_ENTRY head, PLIST_ENTRY node)
- {
- ListEntry_Insert(head->Blink, head, node);
- }
- static __inline void ListEntry_AddHead(PLIST_ENTRY head, PLIST_ENTRY node)
- {
- ListEntry_Insert(head, head->Flink, node);
- }
- static __inline PLIST_ENTRY ListEntry_RemoveListHead(PLIST_ENTRY head)
- {
- PLIST_ENTRY t = head->Flink;
- ListEntry_DeleteNode(t);
- return t;
- }
- static __inline PLIST_ENTRY ListEntry_RemoveListTail(PLIST_ENTRY head)
- {
- PLIST_ENTRY t = head->Blink;
- ListEntry_DeleteNode(t);
- return t;
- }
- static __inline int ListEntry_IsEmpty(PLIST_ENTRY head)
- {
- return head->Blink == head;
- }
- static __inline PLIST_ENTRY ListEntry_GetHead(PLIST_ENTRY head)
- {
- return head->Flink;
- }
- static __inline PLIST_ENTRY ListEntry_GetTail(PLIST_ENTRY head)
- {
- return head->Blink;
- }
- #define ListEntry_ForEachSafe(pos, n, head, type, member) \
- for (pos = CONTAINING_RECORD((head)->Flink, type, member), \
- n = CONTAINING_RECORD(pos->member.Flink, type, member); \
- &pos->member != (head); \
- pos = n, n = CONTAINING_RECORD(n->member.Flink, type, member))
- #define ListEntry_ForEach(pos, head, type, member) \
- for (pos = CONTAINING_RECORD((head)->Flink, type, member); \
- &pos->member != head; \
- pos = CONTAINING_RECORD(pos->member.Flink, type, member))
- #endif // LISTENTRY_H
|