48# define LLIST_MACRO static inline
51# define LLIST_MACRO static __inline__
53# define LLIST_MACRO static
57#if defined(LLIST_INTERFACE)
59#define LLIST_FUNC(proto, ...) proto
60#elif defined(LLIST_IMPLEMENTATION)
62#define LLIST_FUNC(proto, ...) proto { __VA_ARGS__ }
65#define LLIST_FUNC(proto, ...) LLIST_MACRO proto { __VA_ARGS__ }
89#define LLIST_AUTO(name) llist name = {&name,&name}
95#define llist_insert_head(list, element) llist_insert_next (list, element)
96#define llist_insert_tail(list, element) llist_insert_prev (list, element)
97#define llist_head llist_next
98#define llist_tail llist_prev
111#define LLIST_TO_STRUCTP(llist, type, member) \
112 ((type*)(((char*)(llist)) - offsetof(type, member)))
119#define LLIST_FOREACH(list, node) \
120 for (LList node = llist_head (list); \
121 ! llist_is_end (node, list); \
122 llist_forward (&node))
129#define LLIST_FOREACH_REV(list, node) \
130 for (LList node = llist_tail (list); \
131 ! llist_is_end (node, list); \
132 llist_backward (&node))
141#define LLIST_FORRANGE(start, end, node) \
142 for (LList node = start; \
144 llist_forward (&node))
152#define LLIST_FORRANGE_REV(rstart, rend, node) \
153 for (LList node = rstart; \
155 llist_backward (&node))
164#define LLIST_WHILE_HEAD(list, head) \
165 for (LList head = llist_head (list); \
166 !llist_is_empty (list); \
167 head = llist_head (list))
175#define LLIST_WHILE_TAIL(list, tail) \
176 for (LList tail = llist_tail (list); \
177 !llist_is_empty (list); \
178 tail = llist_tail (list))
187 return self->next = self->prev = self;
194 return self->next == self;
202 return self->next->next == self;
211 return self->next == head;
220 return self->prev == tail;
239 for (
const_LList i = member->next; i != member; i = i->next)
254 for (
const_LList i = before->next; i != self; i = i->next)
270 for (; i->next != self; ++cnt, i = i->next);
276 LList nxt = self->next, pre = self->prev;
287 llist_unlink_fast_ (self);
288 return self->next = self->prev = self;
301 return self->next->prev = self->prev->next = self;
312 llist_unlink_fast_ (
next);
313 self->next->prev =
next;
327 llist_unlink_fast_ (
prev);
328 self->prev->next =
prev;
344 if (!llist_is_empty (
next))
364 if (!llist_is_empty (
prev))
383LLIST_FUNC (LList llist_insertafter_range (LList self, LList start, LList end),
401LLIST_FUNC (LList llist_inserbefore_range (LList self, LList start, LList end),
419 LList tmp = self->next->next;
421 self->next->prev = self->prev;
422 self->prev->next = self->next;
423 self->prev = self->next;
424 self->next->next = self;
436 LList tmp = self->prev->prev;
438 self->prev->next = self->next;
439 self->next->prev = self->prev;
440 self->next = self->prev;
441 self->prev->prev = self;
473 *self = (*self)->next;
482 *self = (*self)->prev;
494 self = llist_next (self);
497 self = llist_prev (self);
511 self = llist_next (self);
518 self = llist_prev (self);
551 if (!llist_is_single (self))
554 llist_insert_prev (++n & 1 ? &left : &right, head);
559 while (!llist_is_empty (&left) && !llist_is_empty (&right))
560 llist_insert_prev (self,
cmp (left.next, right.next,
extra) < 0 ? left.next : right.
next);
562 if (!llist_is_empty (&left))
563 llist_insertlist_prev (self, &left);
564 if (!llist_is_empty (&right))
565 llist_insertlist_prev (self, &right);
604 if (llist_next(self) != node)
605 llist_insert_next (self, node);
struct llist_struct * prev
#define LLIST_FUNC(proto,...)
const llist * const_LList
int(* llist_cmpfn)(const_LList a, const_LList b, void *extra)
The comparison function function type.
#define LLIST_WHILE_HEAD(list, head)
Consume a list from head.
const_LList llist_cmpfn cmp
const_LList llist_cmpfn void * extra
#define LLIST_FOREACH(list, node)
Iterate forward over a list.
struct llist_struct * next