1 /* Skippy - Seduces Kids Into Perversion
3 * Copyright (C) 2004 Hyriand <hyriand@thegraveyard.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef SKIPPY_DLIST_H
21 #define SKIPPY_DLIST_H
23 struct dlist_element {
25 struct dlist_element *next;
26 struct dlist_element *prev;
29 typedef struct dlist_element dlist;
31 /* first element in list */
32 dlist *dlist_first(dlist *);
34 /* last element in list */
35 dlist *dlist_last(dlist *);
37 /* add element to the end of the list, returns new element */
38 dlist *dlist_add(dlist *, void *);
40 /* add element to the start of the list, returns new element (and thus, start of list) */
41 dlist *dlist_prepend(dlist *, void *);
43 /* remove an element from the list, returns another element in the list or 0 */
44 dlist *dlist_remove(dlist *);
45 dlist *dlist_remove_free_data(dlist *);
46 dlist *dlist_remove_nth(dlist *, unsigned int n);
47 dlist *dlist_remove_nth_free_data(dlist *, unsigned int n);
49 /* free the list (not the data), returns 0 */
50 dlist *dlist_free(dlist *);
52 /* delete a list calling func on each data item */
53 typedef void (*dlist_free_func)(void *);
54 dlist *dlist_free_with_func(dlist *, dlist_free_func);
56 /* free the data (not the list) */
57 void dlist_free_data(dlist *);
59 /* free both list and data, returns 0 */
60 dlist *dlist_free_with_data(dlist *);
62 /* return the length of the list */
63 unsigned int dlist_len(dlist *);
65 /* check if l1 and l2 are elements of the same list */
66 int dlist_same(dlist *, dlist *);
68 /* reverse a list (swaps data) */
69 void dlist_reverse(dlist *);
71 /* duplicate the list (not the data), returns new end */
72 dlist *dlist_dup(dlist *);
74 /* find all matching elements (returns new list or 0) */
75 typedef int (*dlist_match_func)(dlist*, void *);
76 dlist *dlist_find_all(dlist *, dlist_match_func, void *);
78 /* find an element (returns element or 0) */
79 dlist *dlist_find(dlist *, dlist_match_func, void *);
81 /* find an element whose data pointer matches */
82 dlist *dlist_find_data(dlist *, void *);
84 /* return nth element or 0 */
85 dlist *dlist_nth(dlist *l, unsigned int n);
87 /* swap the data fields of 2 elements */
88 void dlist_swap(dlist *, dlist *);
90 /* sort a list (not very efficient, uses bubble-sort) */
91 typedef int (*dlist_cmp_func)(dlist *, dlist *, void *);
92 void dlist_sort(dlist *, dlist_cmp_func, void *);
94 #endif /* SKIPPY_DLIST_H */