2 Based on gslist.c from glib-1.2.9 (LGPL).
4 Adaption to JACK, Copyright (C) 2002 Kai Vehmanen.
5 - replaced use of gtypes with normal ANSI C types
6 - glib's memory allocation routines replaced with
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
19 You should have received a copy of the GNU Lesser General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #ifndef __jack_jslist_h__
26 #define __jack_jslist_h__
29 #include <jack/systemdeps.h>
35 typedef struct _JSList JSList
;
37 typedef int (*JCompareFunc
) (void* a
, void* b
);
46 jack_slist_alloc (void)
50 new_list
= (JSList
*)malloc(sizeof(JSList
));
52 new_list
->data
= NULL
;
53 new_list
->next
= NULL
;
61 jack_slist_prepend (JSList
* list
, void* data
)
65 new_list
= (JSList
*)malloc(sizeof(JSList
));
67 new_list
->data
= data
;
68 new_list
->next
= list
;
74 #define jack_slist_next(slist) ((slist) ? (((JSList *)(slist))->next) : NULL)
77 jack_slist_last (JSList
*list
)
89 jack_slist_remove_link (JSList
*list
,
101 prev
->next
= tmp
->next
;
118 jack_slist_free (JSList
*list
)
121 JSList
*next
= list
->next
;
129 jack_slist_free_1 (JSList
*list
)
138 jack_slist_remove (JSList
*list
,
148 if (tmp
->data
== data
) {
150 prev
->next
= tmp
->next
;
155 jack_slist_free (tmp
);
169 jack_slist_length (JSList
*list
)
184 jack_slist_find (JSList
*list
,
188 if (list
->data
== data
)
198 jack_slist_copy (JSList
*list
)
200 JSList
*new_list
= NULL
;
205 new_list
= jack_slist_alloc ();
206 new_list
->data
= list
->data
;
210 last
->next
= jack_slist_alloc ();
212 last
->data
= list
->data
;
222 jack_slist_append (JSList
*list
,
228 new_list
= jack_slist_alloc ();
229 new_list
->data
= data
;
232 last
= jack_slist_last (list
);
233 last
->next
= new_list
;
242 jack_slist_sort_merge (JSList
*l1
,
244 JCompareFunc compare_func
)
251 if (compare_func(l1
->data
, l2
->data
) < 0) {
259 l
->next
= l1
? l1
: l2
;
266 jack_slist_sort (JSList
*list
,
267 JCompareFunc compare_func
)
279 while ((l2
= l2
->next
) != NULL
) {
280 if ((l2
= l2
->next
) == NULL
)
287 return jack_slist_sort_merge (jack_slist_sort (list
, compare_func
),
288 jack_slist_sort (l2
, compare_func
),
292 #endif /* __jack_jslist_h__ */