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.1 1997/10/09 04:09:56 crh
31 * This is my library of lists and trees. My hope is to replace all of the
32 * hard coded linked lists that are currently used in Samba with calls to
33 * these modules. This should make the code simpler, smaller, and (I hope)
34 * faster. The tree code, in particular, should speed up processing where
35 * large lists are involved.
39 * Revision 0.2 1997/10/08 03:08:16 crh
40 * Fixed a few forgotten link-ups in Insert(), and fixed the AddHead()
41 * macro, which was passing the wrong value for <After> to Insert().
43 * Revision 0.1 1997/10/07 04:34:38 crh
47 * ========================================================================== **
53 /* ========================================================================== **
56 * ubi_dlNode - This is the basic node structure.
57 * ubi_dlNodePtr - Pointer to a node.
58 * ubi_dlList - This is the list header structure.
59 * ubi_dlListPtr - Pointer to a List (i.e., a list header structure).
63 typedef struct ubi_dlListNode
65 struct ubi_dlListNode *Next;
66 struct ubi_dlListNode *Prev;
69 typedef ubi_dlNode *ubi_dlNodePtr;
78 typedef ubi_dlList *ubi_dlListPtr;
80 /* ========================================================================== **
83 * ubi_dlAddHead - Add a new node at the head of the list.
84 * ubi_dlAddTail - Add a new node at the tail of the list.
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_dlFirst - Return a pointer to the first node in the list, if any.
88 * ubi_dlLast - Return a pointer to the last node in the list, if any.
89 * ubi_dlNext - Given a node, return a pointer to the next node.
90 * ubi_dlPrev - Given a node, return a pointer to the previous node.
93 #define ubi_dlAddHead( L, N ) ubi_dlInsert( (L), (N), NULL )
95 #define ubi_dlAddTail( L, N ) ubi_dlInsert( (L), (N), ((L)->Tail) )
97 #define ubi_dlRemHead( L ) ubi_dlRemove( (L), ((L)->Head) )
99 #define ubi_dlRemTail( L ) ubi_dlRemove( (L), ((L)->Tail) )
101 #define ubi_dlFirst( L ) ((L)->Head)
103 #define ubi_dlLast( L ) ((L)->Tail)
105 #define ubi_dlNext( N ) ((N)->Next)
107 #define ubi_dlPrev( N ) ((N)->Prev)
110 /* ========================================================================== **
111 * Function prototypes...
114 ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr );
115 /* ------------------------------------------------------------------------ **
116 * Initialize a doubly-linked list header.
118 * Input: ListPtr - A pointer to the list structure that is to be
119 * initialized for use.
121 * Output: A pointer to the initialized list header (i.e., same as
124 * ------------------------------------------------------------------------ **
127 ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr,
129 ubi_dlNodePtr After );
130 /* ------------------------------------------------------------------------ **
131 * Insert a new node into the list.
133 * Input: ListPtr - A pointer to the list into which the node is to
135 * New - Pointer to the new node.
136 * After - NULL, or a pointer to a node that is already in the
138 * If NULL, then <New> will be added at the head of the
139 * list, else it will be added following <After>.
141 * Output: A pointer to the node that was inserted into the list (i.e.,
142 * the same as <New>).
144 * ------------------------------------------------------------------------ **
147 ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old );
148 /* ------------------------------------------------------------------------ **
149 * Remove a node from the list.
151 * Input: ListPtr - A pointer to the list from which <Old> is to be
153 * Old - A pointer to the node that is to be removed from the
156 * Output: A pointer to the node that was removed (i.e., <Old>).
158 * ------------------------------------------------------------------------ **
162 /* ================================ The End ================================= */
163 #endif /* ubi_dLinkList_H */