]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - lib/lists.h
Filter: Some people can't pronounce "postfixify" correctly. Let's try "linearize...
[thirdparty/bird.git] / lib / lists.h
index 9153029c199d68836de628c5b4581e3a87d87129..066eafbb0b620df62579903481b7bab27dcfa7ab 100644 (file)
@@ -26,18 +26,36 @@ typedef struct node {
   struct node *next, *prev;
 } node;
 
-typedef struct list {                  /* In fact two overlayed nodes */
-  struct node *head, *null, *tail;
+typedef union list {                   /* In fact two overlayed nodes */
+  struct {                             /* Head node */
+    struct node head_node;
+    void *head_padding;
+  };
+  struct {                             /* Tail node */
+    void *tail_padding;
+    struct node tail_node;
+  };
+  struct {                             /* Split to separate pointers */
+    struct node *head;
+    struct node *null;
+    struct node *tail;
+  };
 } list;
 
+
 #define NODE (node *)
 #define HEAD(list) ((void *)((list).head))
 #define TAIL(list) ((void *)((list).tail))
 #define NODE_NEXT(n) ((void *)((NODE (n))->next))
 #define NODE_VALID(n) ((NODE (n))->next)
 #define WALK_LIST(n,list) for(n=HEAD(list); NODE_VALID(n); n=NODE_NEXT(n))
+#define WALK_LIST2(n,nn,list,pos) \
+  for(nn=(list).head; NODE_VALID(nn) && (n=SKIP_BACK(typeof(*n),pos,nn)); nn=nn->next)
 #define WALK_LIST_DELSAFE(n,nxt,list) \
-     for(n=HEAD(list); nxt=NODE_NEXT(n); n=(void *) nxt)
+  for(n=HEAD(list); nxt=NODE_NEXT(n); n=(void *) nxt)
+#define WALK_LIST2_DELSAFE(n,nn,nxt,list,pos) \
+  for(nn=HEAD(list); (nxt=nn->next) && (n=SKIP_BACK(typeof(*n),pos,nn)); nn=nxt)
+
 /* WALK_LIST_FIRST supposes that called code removes each processed node */
 #define WALK_LIST_FIRST(n,list) \
      while(n=HEAD(list), (NODE (n))->next)
@@ -48,20 +66,21 @@ typedef struct list {                       /* In fact two overlayed nodes */
 
 #define EMPTY_LIST(list) (!(list).head->next)
 
+
+#ifndef _BIRD_LISTS_C_
+#define LIST_INLINE static inline
+#include "lib/lists.c"
+#undef LIST_INLINE
+
+#else /* _BIRD_LISTS_C_ */
+#define LIST_INLINE
 void add_tail(list *, node *);
 void add_head(list *, node *);
 void rem_node(node *);
-void rem2_node(node *);
 void add_tail_list(list *, list *);
 void init_list(list *);
 void insert_node(node *, node *);
-
-#ifndef _BIRD_LISTS_C_
-#define LIST_INLINE extern inline
-#include "lib/lists.c"
-#undef LIST_INLINE
-#else
-#define LIST_INLINE
+uint list_length(list *);
 #endif
 
 #endif