1 /* xdelta 3 - delta compression tools and library
2 * Copyright (C) 2002, 2006, 2007. Joshua P. MacDonald
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __XDELTA3_LIST__
20 #define __XDELTA3_LIST__
22 #define XD3_MAKELIST(LTYPE,ETYPE,LNAME) \
24 static inline ETYPE* \
25 LTYPE ## _entry (LTYPE* l) \
27 return (ETYPE*) ((char*) l - (ptrdiff_t) &((ETYPE*) 0)->LNAME); \
31 LTYPE ## _init (LTYPE *l) \
38 LTYPE ## _add (LTYPE *prev, LTYPE *next, LTYPE *ins) \
47 LTYPE ## _push_back (LTYPE *l, ETYPE *i) \
49 LTYPE ## _add (l->prev, l, & i->LNAME); \
53 LTYPE ## _del (LTYPE *next, \
60 static inline ETYPE* \
61 LTYPE ## _remove (ETYPE *f) \
63 LTYPE *i = f->LNAME.next; \
64 LTYPE ## _del (f->LNAME.next, f->LNAME.prev); \
65 return LTYPE ## _entry (i); \
68 static inline ETYPE* \
69 LTYPE ## _pop_back (LTYPE *l) \
72 LTYPE ## _del (i->next, i->prev); \
73 return LTYPE ## _entry (i); \
76 static inline ETYPE* \
77 LTYPE ## _pop_front (LTYPE *l) \
80 LTYPE ## _del (i->next, i->prev); \
81 return LTYPE ## _entry (i); \
85 LTYPE ## _empty (LTYPE *l) \
87 return l == l->next; \
90 static inline ETYPE* \
91 LTYPE ## _front (LTYPE *f) \
93 return LTYPE ## _entry (f->next); \
96 static inline ETYPE* \
97 LTYPE ## _back (LTYPE *f) \
99 return LTYPE ## _entry (f->prev); \
103 LTYPE ## _end (LTYPE *f, ETYPE *i) \
105 return f == & i->LNAME; \
108 static inline ETYPE* \
109 LTYPE ## _next (ETYPE *f) \
111 return LTYPE ## _entry (f->LNAME.next); \
114 static inline usize_t \
115 LTYPE ## _length (LTYPE *l) \
120 for (p = l->next; p != l; p = p->next) \
128 typedef int unused_ ## LTYPE