8aafd99704ee22141c6d97433fb8c77149d0900b
[kai/samba.git] / source3 / ubi_dLinkList.h
1 #ifndef ubi_dLinkList_H
2 #define ubi_dLinkList_H
3 /* ========================================================================== **
4  *                              ubi_dLinkList.h
5  *
6  *  Copyright (C) 1997 by Christopher R. Hertel
7  *
8  *  Email: crh@ubiqx.mn.org
9  * -------------------------------------------------------------------------- **
10  *  This module implements simple doubly-linked lists.
11  * -------------------------------------------------------------------------- **
12  *
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.
17  *
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.
22  *
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.
26  *
27  * -------------------------------------------------------------------------- **
28  *
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.
36  *
37  * Chris -)-----
38  *
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().
42  *
43  * Revision 0.1  1997/10/07 04:34:38  crh
44  * Initial Revision.
45  *
46  *
47  * ========================================================================== **
48  */
49
50 #include <stdlib.h>
51
52
53 /* ========================================================================== **
54  * Typedefs...
55  *
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).
60  *
61  */
62
63 typedef struct ubi_dlListNode
64   {
65   struct ubi_dlListNode *Next;
66   struct ubi_dlListNode *Prev;
67   } ubi_dlNode;
68
69 typedef ubi_dlNode *ubi_dlNodePtr;
70
71 typedef struct
72   {
73   ubi_dlNodePtr Head;
74   ubi_dlNodePtr Tail;
75   unsigned long count;
76   } ubi_dlList;
77
78 typedef ubi_dlList *ubi_dlListPtr;
79
80 /* ========================================================================== **
81  * Macros...
82  * 
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.
91  */
92
93 #define ubi_dlAddHead( L, N ) ubi_dlInsert( (L), (N), NULL )
94
95 #define ubi_dlAddTail( L, N ) ubi_dlInsert( (L), (N), ((L)->Tail) )
96
97 #define ubi_dlRemHead( L ) ubi_dlRemove( (L), ((L)->Head) )
98
99 #define ubi_dlRemTail( L ) ubi_dlRemove( (L), ((L)->Tail) )
100
101 #define ubi_dlFirst( L ) ((L)->Head)
102
103 #define ubi_dlLast( L )  ((L)->Tail)
104
105 #define ubi_dlNext( N )  ((N)->Next)
106
107 #define ubi_dlPrev( N )  ((N)->Prev)
108
109
110 /* ========================================================================== **
111  * Function prototypes...
112  */
113
114 ubi_dlListPtr ubi_dlInitList( ubi_dlListPtr ListPtr );
115   /* ------------------------------------------------------------------------ **
116    * Initialize a doubly-linked list header.
117    *
118    *  Input:  ListPtr - A pointer to the list structure that is to be
119    *                    initialized for use.
120    *
121    *  Output: A pointer to the initialized list header (i.e., same as
122    *          <ListPtr>).
123    *
124    * ------------------------------------------------------------------------ **
125    */
126
127 ubi_dlNodePtr ubi_dlInsert( ubi_dlListPtr ListPtr,
128                             ubi_dlNodePtr New,
129                             ubi_dlNodePtr After );
130   /* ------------------------------------------------------------------------ **
131    * Insert a new node into the list.
132    *
133    *  Input:  ListPtr - A pointer to the list into which the node is to
134    *                    be inserted.
135    *          New     - Pointer to the new node.
136    *          After   - NULL, or a pointer to a node that is already in the
137    *                    list.
138    *                    If NULL, then <New> will be added at the head of the
139    *                    list, else it will be added following <After>.
140    * 
141    *  Output: A pointer to the node that was inserted into the list (i.e.,
142    *          the same as <New>).
143    *
144    * ------------------------------------------------------------------------ **
145    */
146
147 ubi_dlNodePtr ubi_dlRemove( ubi_dlListPtr ListPtr, ubi_dlNodePtr Old );
148   /* ------------------------------------------------------------------------ **
149    * Remove a node from the list.
150    *
151    *  Input:  ListPtr - A pointer to the list from which <Old> is to be
152    *                    removed.
153    *          Old     - A pointer to the node that is to be removed from the
154    *                    list.
155    *
156    *  Output: A pointer to the node that was removed (i.e., <Old>).
157    *
158    * ------------------------------------------------------------------------ **
159    */
160
161
162 /* ================================ The End ================================= */
163 #endif /* ubi_dLinkList_H */