r3780: final release notes
[Samba.git] / source / ubiqx / ubi_dLinkList.h
blob682e566ee6749b89f1931e719e7e01fcd8e93731
1 #ifndef UBI_DLINKLIST_H
2 #define UBI_DLINKLIST_H
3 /* ========================================================================== **
4 * ubi_dLinkList.h
6 * Copyright (C) 1997, 1998 by Christopher R. Hertel
8 * Email: crh@ubiqx.mn.org
9 * -------------------------------------------------------------------------- **
10 * This module implements simple doubly-linked lists.
11 * -------------------------------------------------------------------------- **
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Library General Public
15 * License as published by the Free Software Foundation; either
16 * version 2 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Library General Public License for more details.
23 * You should have received a copy of the GNU Library General Public
24 * License along with this library; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * -------------------------------------------------------------------------- **
29 * Log: ubi_dLinkList.h,v
30 * Revision 0.11 1999/06/19 16:58:06 crh
31 * Renamed the ubi_slRemove() function in ubi_sLinkList to
32 * ubi_slRemoveNext(). I was bothered by the fact that it didn't
33 * match the functionality of the ubi_dlRemove() function in
34 * ubi_dLinkList. The new name is more 'correct'.
36 * Revision 0.10 1998/07/24 07:30:20 crh
37 * Added the ubi_dlNewList() macro.
39 * Revision 0.9 1998/06/04 21:29:27 crh
40 * Upper-cased defined constants (eg UBI_BINTREE_H) in some header files.
41 * This is more "standard", and is what people expect. Weird, eh?
43 * Revision 0.8 1998/06/03 18:06:03 crh
44 * Further fiddling with sys_include.h, which has been moved from the .c file
45 * to the .h file.
47 * Revision 0.7 1998/06/02 01:38:47 crh
48 * Changed include file name from ubi_null.h to sys_include.h to make it
49 * more generic.
51 * Revision 0.6 1998/05/20 04:38:05 crh
52 * The C file now includes ubi_null.h. See ubi_null.h for more info.
54 * Revision 0.5 1998/03/10 02:54:04 crh
55 * Simplified the code and added macros for stack & queue manipulations.
57 * Revision 0.4 1998/01/03 01:53:44 crh
58 * Added ubi_dlCount() macro.
60 * Revision 0.3 1997/10/15 03:04:31 crh
61 * Added some handy type casting to the macros. Added AddHere and RemThis
62 * macros.
64 * Revision 0.2 1997/10/08 03:08:16 crh
65 * Fixed a few forgotten link-ups in Insert(), and fixed the AddHead()
66 * macro, which was passing the wrong value for <After> to Insert().
68 * Revision 0.1 1997/10/07 04:34:38 crh
69 * Initial Revision.
71 * -------------------------------------------------------------------------- **
72 * This module is similar to the ubi_sLinkList module, but it is neither a
73 * descendant type nor an easy drop-in replacement for the latter. One key
74 * difference is that the ubi_dlRemove() function removes the indicated node,
75 * while the ubi_slRemoveNext() function (in ubi_sLinkList) removes the node
76 * *following* the indicated node.
78 * ========================================================================== **
81 #include "sys_include.h" /* System-specific includes. */
83 /* ========================================================================== **
84 * Typedefs...
86 * ubi_dlNode - This is the basic node structure.
87 * ubi_dlNodePtr - Pointer to a node.
88 * ubi_dlList - This is the list header structure.
89 * ubi_dlListPtr - Pointer to a List (i.e., a list header structure).
93 typedef struct ubi_dlListNode
95 struct ubi_dlListNode *Next;
96 struct ubi_dlListNode *Prev;
97 } ubi_dlNode;
99 typedef ubi_dlNode *ubi_dlNodePtr;
101 typedef struct
103 ubi_dlNodePtr Head;
104 ubi_dlNodePtr Tail;
105 unsigned long count;
106 } ubi_dlList;
108 typedef ubi_dlList *ubi_dlListPtr;
110 /* ========================================================================== **
111 * Macros...
113 * ubi_dlNewList - Macro used to declare and initialize a new list in one
114 * swell foop. It is used when defining a variable of
115 * type ubi_dlList. The definition
116 * static ubi_dlNewList( gerbil );
117 * is translated to
118 * static ubi_dlList gerbil[1] = {{ NULL, NULL, 0 }};
120 * ubi_dlCount - Return the number of entries currently in the list.
122 * ubi_dlAddHead - Add a new node at the head of the list.
123 * ubi_dlAddNext - Add a node following the given node.
124 * ubi_dlAddTail - Add a new node at the tail of the list.
125 * Note: AddTail evaluates the L parameter twice.
127 * ubi_dlRemHead - Remove the node at the head of the list, if any.
128 * Note: RemHead evaluates the L parameter twice.
129 * ubi_dlRemThis - Remove the indicated node.
130 * ubi_dlRemTail - Remove the node at the tail of the list, if any.
131 * Note: RemTail evaluates the L parameter twice.
133 * ubi_dlFirst - Return a pointer to the first node in the list, if any.
134 * ubi_dlLast - Return a pointer to the last node in the list, if any.
135 * ubi_dlNext - Given a node, return a pointer to the next node.
136 * ubi_dlPrev - Given a node, return a pointer to the previous node.
138 * ubi_dlPush - Add a node at the head of the list (synonym of AddHead).
139 * ubi_dlPop - Remove a node at the head of the list (synonym of RemHead).
140 * ubi_dlEnqueue - Add a node at the tail of the list (sysnonym of AddTail).
141 * ubi_dlDequeue - Remove a node at the head of the list (synonym of RemHead).
143 * Note that all of these provide type casting of the parameters. The
144 * Add and Rem macros are nothing more than nice front-ends to the
145 * Insert and Remove operations.
147 * Also note that the First, Next and Last macros do no parameter checking!
151 #define ubi_dlNewList( L ) ubi_dlList (L)[1] = {{ NULL, NULL, 0 }}
153 #define ubi_dlCount( L ) (((ubi_dlListPtr)(L))->count)
155 #define ubi_dlAddHead( L, N ) \
156 ubi_dlInsert( (ubi_dlListPtr)(L), (ubi_dlNodePtr)(N), NULL )
158 #define ubi_dlAddNext( L, N, A ) \
159 ubi_dlInsert( (ubi_dlListPtr)(L), \
160 (ubi_dlNodePtr)(N), \
161 (ubi_dlNodePtr)(A) )
163 #define ubi_dlAddTail( L, N ) \
164 ubi_dlInsert( (ubi_dlListPtr)(L), \
165 (ubi_dlNodePtr)(N), \
166 (((ubi_dlListPtr)(L))->Tail) )
168 #define ubi_dlRemHead( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
169 (((ubi_dlListPtr)(L))->Head) )
171 #define ubi_dlRemThis( L, N ) ubi_dlRemove( (ubi_dlListPtr)(L), \
172 (ubi_dlNodePtr)(N) )
174 #define ubi_dlRemTail( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
175 (((ubi_dlListPtr)(L))->Tail) )
177 #define ubi_dlFirst( L ) (((ubi_dlListPtr)(L))->Head)
179 #define ubi_dlLast( L ) (((ubi_dlListPtr)(L))->Tail)
181 #define ubi_dlNext( N ) (((ubi_dlNodePtr)(N))->Next)
183 #define ubi_dlPrev( N ) (((ubi_dlNodePtr)(N))->Prev)
185 #define ubi_dlPush ubi_dlAddHead
186 #define ubi_dlPop ubi_dlRemHead
187 #define ubi_dlEnqueue ubi_dlAddTail
188 #define ubi_dlDequeue ubi_dlRemHead
190 /* ========================================================================== **
191 * Function prototypes...
194 ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr );
195 /* ------------------------------------------------------------------------ **
196 * Initialize a doubly-linked list header.
198 * Input: ListPtr - A pointer to the list structure that is to be
199 * initialized for use.
201 * Output: A pointer to the initialized list header (i.e., same as
202 * <ListPtr>).
204 * ------------------------------------------------------------------------ **
207 ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr,
208 ubi_dlNodePtr New,
209 ubi_dlNodePtr After );
210 /* ------------------------------------------------------------------------ **
211 * Insert a new node into the list.
213 * Input: ListPtr - A pointer to the list into which the node is to
214 * be inserted.
215 * New - Pointer to the new node.
216 * After - NULL, or a pointer to a node that is already in the
217 * list.
218 * If NULL, then <New> will be added at the head of the
219 * list, else it will be added following <After>.
221 * Output: A pointer to the node that was inserted into the list (i.e.,
222 * the same as <New>).
224 * ------------------------------------------------------------------------ **
227 ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old );
228 /* ------------------------------------------------------------------------ **
229 * Remove a node from the list.
231 * Input: ListPtr - A pointer to the list from which <Old> is to be
232 * removed.
233 * Old - A pointer to the node that is to be removed from the
234 * list.
236 * Output: A pointer to the node that was removed (i.e., <Old>).
238 * ------------------------------------------------------------------------ **
241 /* ================================ The End ================================= */
242 #endif /* UBI_DLINKLIST_H */