lst.h revision 1.45 1 /* $NetBSD: lst.h,v 1.45 2020/08/26 23:00:47 rillig Exp $ */
2
3 /*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * from: @(#)lst.h 8.1 (Berkeley) 6/6/93
35 */
36
37 /*
38 * Copyright (c) 1988, 1989 by Adam de Boor
39 * Copyright (c) 1989 by Berkeley Softworks
40 * All rights reserved.
41 *
42 * This code is derived from software contributed to Berkeley by
43 * Adam de Boor.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Berkeley and its contributors.
57 * 4. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
60 *
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * SUCH DAMAGE.
72 *
73 * from: @(#)lst.h 8.1 (Berkeley) 6/6/93
74 */
75
76 /*-
77 * lst.h --
78 * Header for using the list library
79 */
80 #ifndef MAKE_LST_H
81 #define MAKE_LST_H
82
83 #include <sys/param.h>
84 #include <stdlib.h>
85
86 /*
87 * basic typedef. This is what the Lst_ functions handle
88 */
89
90 typedef struct List *Lst;
91 typedef struct ListNode *LstNode;
92
93 typedef void *LstCopyProc(void *);
94 typedef void LstFreeProc(void *);
95 typedef int LstFindProc(const void *, const void *);
96 typedef int LstActionProc(void *, void *);
97
98 /*
99 * Creation/destruction functions
100 */
101 /* Create a new list */
102 Lst Lst_Init(void);
103 /* Duplicate an existing list */
104 Lst Lst_CopyS(Lst, LstCopyProc);
105 /* Destroy an old one */
106 void Lst_FreeS(Lst);
107 void Lst_DestroyS(Lst, LstFreeProc);
108 /* True if list is empty */
109 Boolean Lst_IsEmpty(Lst);
110 Boolean Lst_IsEmptyS(Lst);
111
112 /*
113 * Functions to modify a list
114 */
115 /* Insert an element before another */
116 void Lst_InsertBeforeS(Lst, LstNode, void *);
117 /* Place an element at the front of a lst. */
118 void Lst_PrependS(Lst, void *);
119 /* Place an element at the end of a lst. */
120 void Lst_AppendS(Lst, void *);
121 /* Remove an element */
122 void Lst_RemoveS(Lst, LstNode);
123 /* Replace a node with a new value */
124 void LstNode_SetS(LstNode, void *);
125 void LstNode_SetNullS(LstNode);
126
127 void Lst_PrependAllS(Lst, Lst);
128 void Lst_AppendAllS(Lst, Lst);
129 void Lst_MoveAllS(Lst, Lst);
130
131 /*
132 * Node-specific functions
133 */
134 /* Return first element in list */
135 LstNode Lst_First(Lst);
136 LstNode Lst_FirstS(Lst);
137 /* Return last element in list */
138 LstNode Lst_Last(Lst);
139 LstNode Lst_LastS(Lst);
140 /* Return successor to given element */
141 LstNode Lst_Succ(LstNode);
142 LstNode Lst_SuccS(LstNode);
143 /* Return predecessor to given element */
144 LstNode Lst_PrevS(LstNode);
145 /* Get datum from LstNode */
146 void *Lst_DatumS(LstNode);
147
148 /*
149 * Functions for entire lists
150 */
151 /* Find an element in a list */
152 LstNode Lst_Find(Lst, LstFindProc, const void *);
153 LstNode Lst_FindS(Lst, LstFindProc, const void *);
154 /* Find an element starting from somewhere */
155 LstNode Lst_FindFrom(Lst, LstNode, LstFindProc, const void *);
156 LstNode Lst_FindFromS(Lst, LstNode, LstFindProc, const void *);
157 /*
158 * See if the given datum is on the list. Returns the LstNode containing
159 * the datum
160 */
161 LstNode Lst_MemberS(Lst, void *);
162 /* Apply a function to all elements of a lst */
163 int Lst_ForEach(Lst, LstActionProc, void *);
164 int Lst_ForEachS(Lst, LstActionProc, void *);
165 /* Apply a function to all elements of a lst starting from a certain point. */
166 int Lst_ForEachFrom(Lst, LstNode, LstActionProc, void *);
167 int Lst_ForEachFromS(Lst, LstNode, LstActionProc, void *);
168 /*
169 * these functions are for dealing with a list as a table, of sorts.
170 * An idea of the "current element" is kept and used by all the functions
171 * between Lst_Open() and Lst_Close().
172 */
173 /* Open the list */
174 ReturnStatus Lst_Open(Lst);
175 void Lst_OpenS(Lst);
176 /* Next element please, or NULL */
177 LstNode Lst_NextS(Lst);
178 /* Finish table access */
179 void Lst_CloseS(Lst);
180
181 /*
182 * for using the list as a queue
183 */
184 /* Place an element at tail of queue */
185 void Lst_EnqueueS(Lst, void *);
186 /* Remove an element from head of queue */
187 void *Lst_DequeueS(Lst);
188
189 #endif /* MAKE_LST_H */
190