Added ubi_sLinkList module which manages simple singly-linked lists.
[samba.git] / source / ubiqx / ubi_sLinkList.h
1 #ifndef ubi_sLinkList_H
2 #define ubi_sLinkList_H
3 /* ========================================================================== **
4  *                              ubi_sLinkList.h
5  *
6  *  Copyright (C) 1997 by Christopher R. Hertel
7  *
8  *  Email: crh@ubiqx.mn.org
9  * -------------------------------------------------------------------------- **
10  *  This module implements a really simple singly-linked list.
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_sLinkList.h,v $
30  * Revision 1.1  1997/10/15 17:59:58  crh
31  * Added ubi_sLinkList module which manages simple singly-linked lists.
32  *
33  * ========================================================================== **
34  */
35
36 #include <stdlib.h>
37
38
39 /* ========================================================================== **
40  * Typedefs...
41  *
42  *  ubi_slNode    - This is the basic node structure.
43  *  ubi_slNodePtr - Pointer to a node.
44  *  ubi_slList    - This is the list header structure.
45  *  ubi_slListPtr - Pointer to a List (i.e., a list header structure).
46  *
47  */
48
49 typedef struct ubi_slListNode
50   {
51   struct ubi_slListNode *Next;
52   } ubi_slNode;
53
54 typedef ubi_slNode *ubi_slNodePtr;
55
56 typedef struct
57   {
58   ubi_slNodePtr Head;
59   unsigned long count;
60   } ubi_slList;
61
62 typedef ubi_slList *ubi_slListPtr;
63
64 /* ========================================================================== **
65  * Macros...
66  * 
67  *  ubi_slAddHead - Add a new node at the head of the list.
68  *  ubi_slRemHead - Remove the node at the head of the list, if any.
69  *  ubi_slFirst   - Return a pointer to the first node in the list, if any.
70  *  ubi_slNext    - Given a node, return a pointer to the next node.
71  *
72  *  Note that all of these provide type casting of the parameters.  The
73  *  Add and Rem macros are nothing more than nice front-ends to the
74  *  Insert and Remove operations.
75  *
76  */
77
78 #define ubi_slAddHead( L, N ) \
79         ubi_slInsert( (ubi_slListPtr)(L), (ubi_slNodePtr)(N) )
80
81 #define ubi_slRemHead( L ) ubi_slRemove( (ubi_slListPtr)(L) )
82
83 #define ubi_slFirst( L ) (((ubi_slListPtr)(L))->Head)
84
85 #define ubi_slNext( N )  (((ubi_slNodePtr)(N))->Next)
86
87
88 /* ========================================================================== **
89  * Function prototypes...
90  */
91
92 ubi_slListPtr ubi_slInitList( ubi_slListPtr ListPtr );
93   /* ------------------------------------------------------------------------ **
94    * Initialize a singly-linked list header.
95    *
96    *  Input:  ListPtr - A pointer to the list structure that is to be
97    *                    initialized for use.
98    *
99    *  Output: A pointer to the initialized list header (i.e., same as
100    *          <ListPtr>).
101    *
102    * ------------------------------------------------------------------------ **
103    */
104
105 ubi_slNodePtr ubi_slInsert( ubi_slListPtr ListPtr,
106                             ubi_slNodePtr New );
107   /* ------------------------------------------------------------------------ **
108    * Insert a new node at the head of the list.
109    *
110    *  Input:  ListPtr - A pointer to the list into which the node is to
111    *                    be inserted.
112    *          New     - Pointer to the node that is to be added to the list.
113    *
114    *  Output: A pointer to the node that was inserted into the list (i.e.,
115    *          the same as <New>).
116    *
117    * ------------------------------------------------------------------------ **
118    */
119
120 ubi_slNodePtr ubi_slRemove( ubi_slListPtr ListPtr );
121   /* ------------------------------------------------------------------------ **
122    * Remove a node from the head of the list.
123    *
124    *  Input:  ListPtr - A pointer to the list from which the node is to be
125    *                    removed.
126    *
127    *  Output: A pointer to the node that was removed.
128    *
129    * ------------------------------------------------------------------------ **
130    */
131
132 /* ================================ The End ================================= */
133 #endif /* ubi_sLinkList_H */