| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#ifndef __XDELTA3_LIST__ |
|---|
| 20 |
#define __XDELTA3_LIST__ |
|---|
| 21 |
|
|---|
| 22 |
#define XD3_MAKELIST(LTYPE,ETYPE,LNAME) \ |
|---|
| 23 |
\ |
|---|
| 24 |
static inline ETYPE* \ |
|---|
| 25 |
LTYPE ## _entry (LTYPE* l) \ |
|---|
| 26 |
{ \ |
|---|
| 27 |
return (ETYPE*) ((char*) l - (unsigned long) &((ETYPE*) 0)->LNAME); \ |
|---|
| 28 |
} \ |
|---|
| 29 |
\ |
|---|
| 30 |
static inline void \ |
|---|
| 31 |
LTYPE ## _init (LTYPE *l) \ |
|---|
| 32 |
{ \ |
|---|
| 33 |
l->next = l; \ |
|---|
| 34 |
l->prev = l; \ |
|---|
| 35 |
} \ |
|---|
| 36 |
\ |
|---|
| 37 |
static inline void \ |
|---|
| 38 |
LTYPE ## _add (LTYPE *prev, LTYPE *next, LTYPE *ins) \ |
|---|
| 39 |
{ \ |
|---|
| 40 |
next->prev = ins; \ |
|---|
| 41 |
prev->next = ins; \ |
|---|
| 42 |
ins->next = next; \ |
|---|
| 43 |
ins->prev = prev; \ |
|---|
| 44 |
} \ |
|---|
| 45 |
\ |
|---|
| 46 |
static inline void \ |
|---|
| 47 |
LTYPE ## _push_back (LTYPE *l, ETYPE *i) \ |
|---|
| 48 |
{ \ |
|---|
| 49 |
LTYPE ## _add (l->prev, l, & i->LNAME); \ |
|---|
| 50 |
} \ |
|---|
| 51 |
\ |
|---|
| 52 |
static inline void \ |
|---|
| 53 |
LTYPE ## _del (LTYPE *next, \ |
|---|
| 54 |
LTYPE *prev) \ |
|---|
| 55 |
{ \ |
|---|
| 56 |
next->prev = prev; \ |
|---|
| 57 |
prev->next = next; \ |
|---|
| 58 |
} \ |
|---|
| 59 |
\ |
|---|
| 60 |
static inline ETYPE* \ |
|---|
| 61 |
LTYPE ## _remove (ETYPE *f) \ |
|---|
| 62 |
{ \ |
|---|
| 63 |
LTYPE *i = f->LNAME.next; \ |
|---|
| 64 |
LTYPE ## _del (f->LNAME.next, f->LNAME.prev); \ |
|---|
| 65 |
return LTYPE ## _entry (i); \ |
|---|
| 66 |
} \ |
|---|
| 67 |
\ |
|---|
| 68 |
static inline ETYPE* \ |
|---|
| 69 |
LTYPE ## _pop_back (LTYPE *l) \ |
|---|
| 70 |
{ \ |
|---|
| 71 |
LTYPE *i = l->prev; \ |
|---|
| 72 |
LTYPE ## _del (i->next, i->prev); \ |
|---|
| 73 |
return LTYPE ## _entry (i); \ |
|---|
| 74 |
} \ |
|---|
| 75 |
\ |
|---|
| 76 |
static inline ETYPE* \ |
|---|
| 77 |
LTYPE ## _pop_front (LTYPE *l) \ |
|---|
| 78 |
{ \ |
|---|
| 79 |
LTYPE *i = l->next; \ |
|---|
| 80 |
LTYPE ## _del (i->next, i->prev); \ |
|---|
| 81 |
return LTYPE ## _entry (i); \ |
|---|
| 82 |
} \ |
|---|
| 83 |
\ |
|---|
| 84 |
static inline int \ |
|---|
| 85 |
LTYPE ## _empty (LTYPE *l) \ |
|---|
| 86 |
{ \ |
|---|
| 87 |
return l == l->next; \ |
|---|
| 88 |
} \ |
|---|
| 89 |
\ |
|---|
| 90 |
static inline ETYPE* \ |
|---|
| 91 |
LTYPE ## _front (LTYPE *f) \ |
|---|
| 92 |
{ \ |
|---|
| 93 |
return LTYPE ## _entry (f->next); \ |
|---|
| 94 |
} \ |
|---|
| 95 |
\ |
|---|
| 96 |
static inline ETYPE* \ |
|---|
| 97 |
LTYPE ## _back (LTYPE *f) \ |
|---|
| 98 |
{ \ |
|---|
| 99 |
return LTYPE ## _entry (f->prev); \ |
|---|
| 100 |
} \ |
|---|
| 101 |
\ |
|---|
| 102 |
static inline int \ |
|---|
| 103 |
LTYPE ## _end (LTYPE *f, ETYPE *i) \ |
|---|
| 104 |
{ \ |
|---|
| 105 |
return f == & i->LNAME; \ |
|---|
| 106 |
} \ |
|---|
| 107 |
\ |
|---|
| 108 |
static inline ETYPE* \ |
|---|
| 109 |
LTYPE ## _next (ETYPE *f) \ |
|---|
| 110 |
{ \ |
|---|
| 111 |
return LTYPE ## _entry (f->LNAME.next); \ |
|---|
| 112 |
} \ |
|---|
| 113 |
\ |
|---|
| 114 |
static inline int \ |
|---|
| 115 |
LTYPE ## _length (LTYPE *l) \ |
|---|
| 116 |
{ \ |
|---|
| 117 |
LTYPE *p; \ |
|---|
| 118 |
int c = 0; \ |
|---|
| 119 |
\ |
|---|
| 120 |
for (p = l->next; p != l; p = p->next) \ |
|---|
| 121 |
{ \ |
|---|
| 122 |
c += 1; \ |
|---|
| 123 |
} \ |
|---|
| 124 |
\ |
|---|
| 125 |
return c; \ |
|---|
| 126 |
} \ |
|---|
| 127 |
\ |
|---|
| 128 |
typedef int unused_ ## LTYPE |
|---|
| 129 |
|
|---|
| 130 |
#endif |
|---|
| 131 |
|
|---|