1 #ifndef ubi_dLinkList_H
2 #define ubi_dLinkList_H
3 /* ========================================================================== **
6 * Copyright (C) 1997 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 1.2 1997/10/15 03:11:46 crh
31 * These are the ubiqx modules, as included with the Samba distribution.
32 * Updated the linked list module, which has new and changed macros.
34 * Revision 0.3 1997/10/15 03:04:31 crh
35 * Added some handy type casting to the macros. Added AddHere and RemThis
38 * Revision 0.2 1997/10/08 03:08:16 crh
39 * Fixed a few forgotten link-ups in Insert(), and fixed the AddHead()
40 * macro, which was passing the wrong value for <After> to Insert().
42 * Revision 0.1 1997/10/07 04:34:38 crh
46 * ========================================================================== **
52 /* ========================================================================== **
55 * ubi_dlNode - This is the basic node structure.
56 * ubi_dlNodePtr - Pointer to a node.
57 * ubi_dlList - This is the list header structure.
58 * ubi_dlListPtr - Pointer to a List (i.e., a list header structure).
62 typedef struct ubi_dlListNode
64 struct ubi_dlListNode *Next;
65 struct ubi_dlListNode *Prev;
68 typedef ubi_dlNode *ubi_dlNodePtr;
77 typedef ubi_dlList *ubi_dlListPtr;
79 /* ========================================================================== **
82 * ubi_dlAddHead - Add a new node at the head of the list.
83 * ubi_dlAddTail - Add a new node at the tail of the list.
84 * ubi_dlAddHere - Add a node following the given node.
85 * ubi_dlRemHead - Remove the node at the head of the list, if any.
86 * ubi_dlRemTail - Remove the node at the tail of the list, if any.
87 * ubi_dlRemThis - Remove the indicated node.
88 * ubi_dlFirst - Return a pointer to the first node in the list, if any.
89 * ubi_dlLast - Return a pointer to the last node in the list, if any.
90 * ubi_dlNext - Given a node, return a pointer to the next node.
91 * ubi_dlPrev - Given a node, return a pointer to the previous node.
93 * Note that all of these provide type casting of the parameters. The
94 * Add and Rem macros are nothing more than nice front-ends to the
95 * Insert and Remove operations.
99 #define ubi_dlAddHead( L, N ) \
100 ubi_dlInsert( (ubi_dlListPtr)(L), (ubi_dlNodePtr)(N), NULL )
102 #define ubi_dlAddTail( L, N ) \
103 ubi_dlInsert( (ubi_dlListPtr)(L), \
104 (ubi_dlNodePtr)(N), \
105 (((ubi_dlListPtr)(L))->Tail) )
107 #define ubi_dlAddHere( L, N, P ) \
108 ubi_dlInsert( (ubi_dlListPtr)(L), \
109 (ubi_dlNodePtr)(N), \
112 #define ubi_dlRemHead( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
113 (((ubi_dlListPtr)(L))->Head) )
115 #define ubi_dlRemTail( L ) ubi_dlRemove( (ubi_dlListPtr)(L), \
116 (((ubi_dlListPtr)(L))->Tail) )
118 #define ubi_dlRemThis( L, N ) ubi_dlRemove( (ubi_dlListPtr)(L), \
121 #define ubi_dlFirst( L ) (((ubi_dlListPtr)(L))->Head)
123 #define ubi_dlLast( L ) (((ubi_dlListPtr)(L))->Tail)
125 #define ubi_dlNext( N ) (((ubi_dlNodePtr)(N))->Next)
127 #define ubi_dlPrev( N ) (((ubi_dlNodePtr)(N))->Prev)
130 /* ========================================================================== **
131 * Function prototypes...
134 ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr );
135 /* ------------------------------------------------------------------------ **
136 * Initialize a doubly-linked list header.
138 * Input: ListPtr - A pointer to the list structure that is to be
139 * initialized for use.
141 * Output: A pointer to the initialized list header (i.e., same as
144 * ------------------------------------------------------------------------ **
147 ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr,
149 ubi_dlNodePtr After );
150 /* ------------------------------------------------------------------------ **
151 * Insert a new node into the list.
153 * Input: ListPtr - A pointer to the list into which the node is to
155 * New - Pointer to the new node.
156 * After - NULL, or a pointer to a node that is already in the
158 * If NULL, then <New> will be added at the head of the
159 * list, else it will be added following <After>.
161 * Output: A pointer to the node that was inserted into the list (i.e.,
162 * the same as <New>).
164 * ------------------------------------------------------------------------ **
167 ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old );
168 /* ------------------------------------------------------------------------ **
169 * Remove a node from the list.
171 * Input: ListPtr - A pointer to the list from which <Old> is to be
173 * Old - A pointer to the node that is to be removed from the
176 * Output: A pointer to the node that was removed (i.e., <Old>).
178 * ------------------------------------------------------------------------ **
182 /* ================================ The End ================================= */
183 #endif /* ubi_dLinkList_H */