4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _VOLUME_DLIST_H
28 #define _VOLUME_DLIST_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
36 #include <sys/types.h>
39 * Structure defining a doubly linked list of arbitrary objects
41 typedef struct dlist
{
52 extern const boolean_t ASCENDING
;
53 extern const boolean_t DESCENDING
;
54 extern const boolean_t AT_TAIL
;
55 extern const boolean_t AT_HEAD
;
67 * doubly linked list utility methods
71 * count the number of elements currently in the list
73 extern int dlist_length(dlist_t
*list
);
76 * Traverse the list pointed to by head and free each
77 * list node. If freefunc is non-NULL, call freefunc
78 * for each node's object.
80 extern void dlist_free_items(dlist_t
*list
, void (freefunc(void *)));
83 * append item to list. If atend is true, the item is
84 * added at the end of the list, otherwise it is added
87 * returns the possibly changed head of the list.
89 extern dlist_t
*dlist_append(
95 * Create a dlist_t element for the given object and append to list.
98 * the obj member of the dlist_t element to be created
101 * the list to which to append the new dlist_t element
104 * whether to append at the beginning (AT_HEAD) or end
105 * (AT_TAIL) of the list
111 * if a dlist_t could not be allocated
113 extern int dlist_append_object(
119 * Appends list2 to the end of list1.
121 * Returns the resulting list.
123 extern dlist_t
*dlist_append_list(
128 * Remove the first node pointing to same content as item from list,
129 * clear it's next and prev pointers, return new list head.
131 * The caller is responsible for freeing the removed item if it is no
134 * The comparison function should be of the form:
136 * int compare(void *obj1, void* obj2);
138 * When called, obj1 will be the object passed into
139 * dlist_remove_equivalent_item and obj2 will be an object pointed to by an
142 * The function should return 0 if the two objects are equivalent The
143 * function should return nonzero otherwise
146 * the list containing the item to remove
149 * the object with which to compare each item
152 * the comparison function, passed obj and the obj member
153 * of each item, to return 0 if item should be removed
156 * RETURN: the removed item, or NULL if none was found
158 * @return the first element of the resulting list
160 extern dlist_t
*dlist_remove_equivalent_item(
163 int (compare
)(void *obj1
, void *obj2
),
167 * Remove an item from its list. Return the resulting list.
170 * the item to remove, with prev and next pointers
173 * @return the first element of the resulting list
180 * allocates memory for a new list item. The list item will
183 * returns the new list item.
185 extern dlist_t
*dlist_new_item(void *obj
);
188 * inserts item in the correct position within the list based on
189 * the comparison function. if ascending is true, the list will
190 * be in ascending order, otherwise descending.
192 * the comparison function should be of the form:
194 * int compare(void *obj1, void *obj2);
196 * When called, obj1 will be the object pointed to by the item to
197 * be added to the list, obj2 will be an object pointed to by an
198 * item currently in the list.
200 * The function should return 0 if the two objects are equivalent
201 * The function should return <0 if obj1 comes before obj2
202 * The function should return >0 if obj1 comes after obj2
204 * dlist_insert_ordered returns the possibly changed head
207 extern dlist_t
*dlist_insert_ordered(
211 int (compare
)(void *obj1
, void *obj2
));
214 * Locates the item in the list which contains object.
216 * the comparison function should be of the form:
218 * int compare(void *obj1, void *obj2);
220 * When called, obj1 will be the input object, obj2 will be
221 * an object pointed to by an item currently in the list.
223 * The function should return 0 if the two objects are equivalent
224 * The function should return non-zero otherwise
226 * dlist_find() returns the found item or NULL if one was not found.
228 extern dlist_t
*dlist_find(
231 int (compare
)(void *obj1
, void *obj2
));
234 * Determines if list has an item which contains object.
236 * the comparison function should be of the form:
238 * int compare(void *obj1, void *obj2);
240 * When called, obj1 will be the input object, obj2 will be
241 * an object pointed to by an item currently in the list.
243 * The function should return 0 if the two objects are equivalent
244 * The function should return non-zero otherwise
246 * dlist_contains() returns TRUE if the object is already
247 * in the list or FALSE otherwise.
249 extern boolean_t
dlist_contains(
252 int (compare
)(void *obj1
, void *obj2
));
255 * Order the given list such that the number of similar elements
256 * adjacent to each other are minimized. Two elements are considered
257 * similar if the given compare function returns 0.
263 * the comparison function, passed the obj members
264 * of two items, to return 0 if the items can be
267 * @return the first element of the resulting list
270 dlist_separate_similar_elements(
272 int(*equals
)(void *, void *));
278 #endif /* _VOLUME_DLIST_H */