]> mj.ucw.cz Git - libucw.git/blob - lib/lists.c
Implemented an asynchronous I/O library module.
[libucw.git] / lib / lists.c
1 /*
2  *      UCW Library -- Linked Lists
3  *
4  *      (c) 1997--1999 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #include "lib/lib.h"
11
12 #define _UCW_LISTS_C
13 #include "lib/lists.h"
14
15 LIST_INLINE void
16 add_tail(list *l, node *n)
17 {
18   node *z = l->tail;
19
20   n->next = (node *) &l->null;
21   n->prev = z;
22   z->next = n;
23   l->tail = n;
24 }
25
26 LIST_INLINE void
27 add_head(list *l, node *n)
28 {
29   node *z = l->head;
30
31   n->next = z;
32   n->prev = (node *) &l->head;
33   z->prev = n;
34   l->head = n;
35 }
36
37 LIST_INLINE void
38 insert_node(node *n, node *after)
39 {
40   node *z = after->next;
41
42   n->next = z;
43   n->prev = after;
44   after->next = n;
45   z->prev = n;
46 }
47
48 LIST_INLINE void
49 rem_node(node *n)
50 {
51   node *z = n->prev;
52   node *x = n->next;
53
54   z->next = x;
55   x->prev = z;
56 }
57
58 LIST_INLINE void
59 init_list(list *l)
60 {
61   l->head = (node *) &l->null;
62   l->null = NULL;
63   l->tail = (node *) &l->head;
64 }
65
66 LIST_INLINE void
67 add_tail_list(list *to, list *l)
68 {
69   node *p = to->tail;
70   node *q = l->head;
71
72   p->next = q;
73   q->prev = p;
74   q = l->tail;
75   q->next = (node *) &to->null;
76   to->tail = q;
77 }