Browse Source

Add *_APPEND_ELEM macros for appending after given element

Thilo Schulz 9 năm trước cách đây
mục cha
commit
a3ed1e3004
1 tập tin đã thay đổi với 24 bổ sung0 xóa
  1. 24 0
      src/utlist.h

+ 24 - 0
src/utlist.h

@@ -497,6 +497,15 @@ do {
  }                                                                                             \
 } while (0)                                                                                    \
 
+#define LL_APPEND_ELEM(head, el, add)                                                          \
+do {                                                                                           \
+ assert(head != NULL);                                                                         \
+ assert(el != NULL);                                                                           \
+ assert(add != NULL);                                                                          \
+ (add)->next = (el)->next;                                                                     \
+ (el)->next = (add);                                                                           \
+} while (0)                                                                                    \
+
 
 /******************************************************************************
  * doubly linked list macros (non-circular)                                   *
@@ -641,6 +650,21 @@ do {
  }                                                                                             \
 } while (0)                                                                                    \
 
+#define DL_APPEND_ELEM(head, el, add)                                                          \
+do {                                                                                           \
+ assert(head != NULL);                                                                         \
+ assert(el != NULL);                                                                           \
+ assert(add != NULL);                                                                          \
+ (add)->next = (el)->next;                                                                     \
+ (add)->prev = (el);                                                                           \
+ (el)->next = (add);                                                                           \
+ if ((add)->next) {                                                                            \
+  (add)->next->prev = (add);                                                                   \
+ } else {                                                                                      \
+  (head)->prev = (add);                                                                        \
+ }                                                                                             \
+} while (0)                                                                                    \
+
 
 /******************************************************************************
  * circular doubly linked list macros                                         *