1 #ifndef ubi_dLinkList_H
2 #define ubi_dLinkList_H
3 /* ========================================================================== **
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.8 1998/06/03 18:06:03 crh
31 * Further fiddling with sys_include.h, which has been moved from the .c file
34 * Revision 0.7 1998/06/02 01:38:47 crh
35 * Changed include file name from ubi_null.h to sys_include.h to make it
38 * Revision 0.6 1998/05/20 04:38:05 crh
39 * The C file now includes ubi_null.h. See ubi_null.h for more info.
41 * Revision 0.5 1998/03/10 02:54:04 crh
42 * Simplified the code and added macros for stack & queue manipulations.
44 * Revision 0.4 1998/01/03 01:53:44 crh
45 * Added ubi_dlCount() macro.
47 * Revision 0.3 1997/10/15 03:04:31 crh
48 * Added some handy type casting to the macros. Added AddHere and RemThis
51 * Revision 0.2 1997/10/08 03:08:16 crh
52 * Fixed a few forgotten link-ups in Insert(), and fixed the AddHead()
53 * macro, which was passing the wrong value for <After> to Insert().
55 * Revision 0.1 1997/10/07 04:34:38 crh
58 * -------------------------------------------------------------------------- **
59 * This module is similar to the ubi_sLinkList module, but it is neither a
60 * descendant type nor an easy drop-in replacement for the latter. One key
61 * difference is that the ubi_dlRemove() function removes the indicated node,
62 * while the ubi_slRemove() function (in ubi_sLinkList) removes the node
63 * *following* the indicated node.
65 * ========================================================================== **
68 #include "sys_include.h" /* System-specific includes. */
70 /* ========================================================================== **
73 * ubi_dlNode - This is the basic node structure.
74 * ubi_dlNodePtr - Pointer to a node.
75 * ubi_dlList - This is the list header structure.
76 * ubi_dlListPtr - Pointer to a List (i.e., a list header structure).
80 typedef struct ubi_dlListNode
82 struct ubi_dlListNode *Next;
83 struct ubi_dlListNode *Prev;
86 typedef ubi_dlNode *ubi_dlNodePtr;
95 typedef ubi_dlList *ubi_dlListPtr;
97 /* ========================================================================== **
100 * ubi_dlCount - Return the number of entries currently in the list.
102 * ubi_dlAddHead - Add a new node at the head of the list.
103 * ubi_dlAddNext - Add a node following the given node.
104 * ubi_dlAddTail - Add a new node at the tail of the list.
105 * Note: AddTail evaluates the L parameter twice.
107 * ubi_dlRemHead - Remove the node at the head of the list, if any.
108 * Note: RemHead evaluates the L parameter twice.
109 * ubi_dlRemThis - Remove the indicated node.
110 * ubi_dlRemTail - Remove the node at the tail of the list, if any.
111 * Note: RemTail evaluates the L parameter twice.
113 * ubi_dlFirst - Return a pointer to the first node in the list, if any.
114 * ubi_dlLast - Return a pointer to the last node in the list, if any.
115 * ubi_dlNext - Given a node, return a pointer to the next node.
116 * ubi_dlPrev - Given a node, return a pointer to the previous node.
118 * ubi_dlPush - Add a node at the head of the list (synonym of AddHead).
119 * ubi_dlPop - Remove a node at the head of the list (synonym of RemHead).
120 * ubi_dlEnqueue - Add a node at the tail of the list (sysnonym of AddTail).
121 * ubi_dlDequeue - Remove a node at the head of the list (synonym of RemHead).
123 * Note that all of these provide type casting of the parameters. The
124 * Add and Rem macros are nothing more than nice front-ends to the
125 * Insert and Remove operations.
127 * Also note that there the First, Next and Last macros do no parameter
132 #define ubi_dlCount( L ) (((ubi_dlListPtr)(L))->count)
134 #define ubi_dlAddHead( L, N ) \
135 ubi_dlInsert( (ubi_dlListPtr)(L), (ubi_dlNodePtr)(N), NULL )
137 #define ubi_dlAddNext( L, N, A ) \
138 ubi_dlInsert( (ubi_dlListPtr)(L), \
139 (ubi_dlNodePtr)(N), \
142 #define ubi_dlAddTail( L, N ) \
143 ubi_dlInsert( (ubi_dlListPtr)(L), \
144 (ubi_dlNodePtr)(N), \
145 (((ubi_dlListPtr)(L))->Tail) )
147 #define ubi_dlRemHead( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
148 (((ubi_dlListPtr)(L))->Head) )
150 #define ubi_dlRemThis( L, N ) ubi_dlRemove( (ubi_dlListPtr)(L), \
153 #define ubi_dlRemTail( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
154 (((ubi_dlListPtr)(L))->Tail) )
156 #define ubi_dlFirst( L ) (((ubi_dlListPtr)(L))->Head)
158 #define ubi_dlLast( L ) (((ubi_dlListPtr)(L))->Tail)
160 #define ubi_dlNext( N ) (((ubi_dlNodePtr)(N))->Next)
162 #define ubi_dlPrev( N ) (((ubi_dlNodePtr)(N))->Prev)
164 #define ubi_dlPush ubi_dlAddHead
165 #define ubi_dlPop ubi_dlRemHead
166 #define ubi_dlEnqueue ubi_dlAddTail
167 #define ubi_dlDequeue ubi_dlRemHead
169 /* ========================================================================== **
170 * Function prototypes...
173 ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr );
174 /* ------------------------------------------------------------------------ **
175 * Initialize a doubly-linked list header.
177 * Input: ListPtr - A pointer to the list structure that is to be
178 * initialized for use.
180 * Output: A pointer to the initialized list header (i.e., same as
183 * ------------------------------------------------------------------------ **
186 ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr,
188 ubi_dlNodePtr After );
189 /* ------------------------------------------------------------------------ **
190 * Insert a new node into the list.
192 * Input: ListPtr - A pointer to the list into which the node is to
194 * New - Pointer to the new node.
195 * After - NULL, or a pointer to a node that is already in the
197 * If NULL, then <New> will be added at the head of the
198 * list, else it will be added following <After>.
200 * Output: A pointer to the node that was inserted into the list (i.e.,
201 * the same as <New>).
203 * ------------------------------------------------------------------------ **
206 ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old );
207 /* ------------------------------------------------------------------------ **
208 * Remove a node from the list.
210 * Input: ListPtr - A pointer to the list from which <Old> is to be
212 * Old - A pointer to the node that is to be removed from the
215 * Output: A pointer to the node that was removed (i.e., <Old>).
217 * ------------------------------------------------------------------------ **
220 /* ================================ The End ================================= */
221 #endif /* ubi_dLinkList_H */