Mercury
mercury_list.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2005-2008, Simon Howard
4 
5 Permission to use, copy, modify, and/or distribute this software
6 for any purpose with or without fee is hereby granted, provided
7 that the above copyright notice and this permission notice appear
8 in all copies.
9 
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
14 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 
19  */
20 
52 #ifndef MERCURY_LIST_H
53 #define MERCURY_LIST_H
54 
55 #include "mercury_util_config.h"
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
68 typedef struct hg_list_entry hg_list_entry_t;
69 
75 
80 typedef void *hg_list_value_t;
81 
86 struct hg_list_iter {
89 };
90 
95 #define HG_LIST_NULL ((void *) 0)
96 
107 typedef int (*hg_list_compare_func_t)(hg_list_value_t value1, hg_list_value_t value2);
108 
119 typedef int (*hg_list_equal_func_t)(hg_list_value_t value1, hg_list_value_t value2);
120 
126 HG_UTIL_EXPORT void
128 
137 HG_UTIL_EXPORT hg_list_entry_t *
138 hg_list_prepend(hg_list_entry_t **list, hg_list_value_t data);
139 
148 HG_UTIL_EXPORT hg_list_entry_t *
149 hg_list_append(hg_list_entry_t **list, hg_list_value_t data);
150 
158 HG_UTIL_EXPORT hg_list_entry_t *
159 hg_list_prev(hg_list_entry_t *listentry);
160 
168 HG_UTIL_EXPORT hg_list_entry_t *
169 hg_list_next(hg_list_entry_t *listentry);
170 
177 HG_UTIL_EXPORT hg_list_value_t
178 hg_list_data(hg_list_entry_t *listentry);
179 
187 HG_UTIL_EXPORT hg_list_entry_t *
188 hg_list_nth_entry(hg_list_entry_t *list, unsigned int n);
189 
198 HG_UTIL_EXPORT hg_list_value_t
199 hg_list_nth_data(hg_list_entry_t *list, unsigned int n);
200 
207 HG_UTIL_EXPORT unsigned int
209 
219 HG_UTIL_EXPORT hg_list_value_t *
221 
230 HG_UTIL_EXPORT int
232 
242 HG_UTIL_EXPORT unsigned int
244  hg_list_value_t data);
245 
252 HG_UTIL_EXPORT void
254 
265 HG_UTIL_EXPORT hg_list_entry_t *
267  hg_list_equal_func_t callback,
268  hg_list_value_t data);
269 
276 HG_UTIL_EXPORT void
278 
287 HG_UTIL_EXPORT int
289 
297 HG_UTIL_EXPORT hg_list_value_t
299 
306 HG_UTIL_EXPORT void
308 
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 #endif /* MERCURY_LIST_H */
314 
void * hg_list_value_t
A value stored in a list.
Definition: mercury_list.h:80
HG_UTIL_EXPORT int hg_list_remove_entry(hg_list_entry_t **list, hg_list_entry_t *entry)
Remove an entry from a list.
HG_UTIL_EXPORT hg_list_value_t hg_list_data(hg_list_entry_t *listentry)
Retrieve the value at a list entry.
int(* hg_list_compare_func_t)(hg_list_value_t value1, hg_list_value_t value2)
Callback function used to compare values in a list when sorting.
Definition: mercury_list.h:107
HG_UTIL_EXPORT hg_list_value_t hg_list_iter_next(hg_list_iter_t *iterator)
Using a list iterator, retrieve the next value from the list.
hg_list_entry_t ** prev_next
Definition: mercury_list.h:87
Definition of a hg_list_iter_t.
Definition: mercury_list.h:86
HG_UTIL_EXPORT hg_list_entry_t * hg_list_prev(hg_list_entry_t *listentry)
Retrieve the previous entry in a list.
HG_UTIL_EXPORT unsigned int hg_list_remove_data(hg_list_entry_t **list, hg_list_equal_func_t callback, hg_list_value_t data)
Remove all occurrences of a particular value from a list.
HG_UTIL_EXPORT void hg_list_free(hg_list_entry_t *list)
Free an entire list.
HG_UTIL_EXPORT int hg_list_iter_has_more(hg_list_iter_t *iterator)
Determine if there are more values in the list to iterate over.
HG_UTIL_EXPORT unsigned int hg_list_length(hg_list_entry_t *list)
Find the length of a list.
HG_UTIL_EXPORT void hg_list_iterate(hg_list_entry_t **list, hg_list_iter_t *iter)
Initialize a hg_list_iter_t structure to iterate over a list.
HG_UTIL_EXPORT hg_list_entry_t * hg_list_nth_entry(hg_list_entry_t *list, unsigned int n)
Retrieve the entry at a specified index in a list.
HG_UTIL_EXPORT hg_list_value_t * hg_list_to_array(hg_list_entry_t *list)
Create a C array containing the contents of a list.
HG_UTIL_EXPORT void hg_list_sort(hg_list_entry_t **list, hg_list_compare_func_t compare_func)
Sort a list.
HG_UTIL_EXPORT hg_list_entry_t * hg_list_find_data(hg_list_entry_t *list, hg_list_equal_func_t callback, hg_list_value_t data)
Find the entry for a particular value in a list.
int(* hg_list_equal_func_t)(hg_list_value_t value1, hg_list_value_t value2)
Callback function used to determine of two values in a list are equal.
Definition: mercury_list.h:119
HG_UTIL_EXPORT void hg_list_iter_remove(hg_list_iter_t *iterator)
Delete the current entry in the list (the value last returned from list_iter_next) ...
hg_list_entry_t * current
Definition: mercury_list.h:88
struct hg_list_entry hg_list_entry_t
Represents an entry in a doubly-linked list.
Definition: mercury_list.h:68
HG_UTIL_EXPORT hg_list_entry_t * hg_list_next(hg_list_entry_t *listentry)
Retrieve the next entry in a list.
HG_UTIL_EXPORT hg_list_entry_t * hg_list_append(hg_list_entry_t **list, hg_list_value_t data)
Append a value to the end of a list.
HG_UTIL_EXPORT hg_list_value_t hg_list_nth_data(hg_list_entry_t *list, unsigned int n)
Retrieve the value at a specified index in the list.
HG_UTIL_EXPORT hg_list_entry_t * hg_list_prepend(hg_list_entry_t **list, hg_list_value_t data)
Prepend a value to the start of a list.