]> mj.ucw.cz Git - libucw.git/blob - lib/lists.c
Modified verbose mode.
[libucw.git] / lib / lists.c
1 /*
2  *      Sherlock Library -- Linked Lists
3  *
4  *      (c) 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <stdio.h>
8
9 #define _SHERLOCK_LISTS_C
10 #include "lists.h"
11
12 LIST_INLINE void
13 add_tail(list *l, node *n)
14 {
15   node *z = l->tail;
16
17   n->next = (node *) &l->null;
18   n->prev = z;
19   z->next = n;
20   l->tail = n;
21 }
22
23 LIST_INLINE void
24 add_head(list *l, node *n)
25 {
26   node *z = l->head;
27
28   n->next = z;
29   n->prev = (node *) &l->head;
30   z->prev = n;
31   l->head = n;
32 }
33
34 LIST_INLINE void
35 insert_node(node *n, node *after)
36 {
37   node *z = after->next;
38
39   n->next = z;
40   n->prev = after;
41   after->next = n;
42   z->prev = n;
43 }
44
45 LIST_INLINE void
46 rem_node(node *n)
47 {
48   node *z = n->prev;
49   node *x = n->next;
50
51   z->next = x;
52   x->prev = z;
53 }
54
55 LIST_INLINE void
56 init_list(list *l)
57 {
58   l->head = (node *) &l->null;
59   l->null = NULL;
60   l->tail = (node *) &l->head;
61 }
62
63 LIST_INLINE void
64 add_tail_list(list *to, list *l)
65 {
66   node *p = to->tail;
67   node *q = l->head;
68
69   p->next = q;
70   q->prev = p;
71   q = l->tail;
72   q->next = (node *) &to->null;
73   to->tail = q;
74 }