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 memery 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.
23 $Id: jslist.h,v 1.2 2005/11/23 11:24:29 letz Exp $
26 #ifndef __jack_jslist_h__
27 #define __jack_jslist_h__
31 typedef struct _JSList JSList
;
33 typedef int (*JCompareFunc
) (void* a
,
43 jack_slist_alloc (void)
47 new_list
= (JSList
*)malloc(sizeof(JSList
));
48 new_list
->data
= NULL
;
49 new_list
->next
= NULL
;
56 jack_slist_prepend (JSList
*list
,
61 new_list
= (JSList
*)malloc(sizeof(JSList
));
62 new_list
->data
= data
;
63 new_list
->next
= list
;
68 #define jack_slist_next(slist) ((slist) ? (((JSList *)(slist))->next) : NULL)
71 jack_slist_last (JSList
*list
)
83 jack_slist_remove_link (JSList
*list
,
95 prev
->next
= tmp
->next
;
112 jack_slist_free (JSList
*list
)
115 JSList
*next
= list
->next
;
123 jack_slist_free_1 (JSList
*list
)
132 jack_slist_remove (JSList
*list
,
142 if (tmp
->data
== data
) {
144 prev
->next
= tmp
->next
;
149 jack_slist_free (tmp
);
163 jack_slist_length (JSList
*list
)
178 jack_slist_find (JSList
*list
,
182 if (list
->data
== data
)
192 jack_slist_copy (JSList
*list
)
194 JSList
*new_list
= NULL
;
199 new_list
= jack_slist_alloc ();
200 new_list
->data
= list
->data
;
204 last
->next
= jack_slist_alloc ();
206 last
->data
= list
->data
;
216 jack_slist_append (JSList
*list
,
222 new_list
= jack_slist_alloc ();
223 new_list
->data
= data
;
226 last
= jack_slist_last (list
);
227 last
->next
= new_list
;
236 jack_slist_sort_merge (JSList
*l1
,
238 JCompareFunc compare_func
)
245 if (compare_func(l1
->data
, l2
->data
) < 0) {
253 l
->next
= l1
? l1
: l2
;
260 jack_slist_sort (JSList
*list
,
261 JCompareFunc compare_func
)
273 while ((l2
= l2
->next
) != NULL
) {
274 if ((l2
= l2
->next
) == NULL
)
281 return jack_slist_sort_merge (jack_slist_sort (list
, compare_func
),
282 jack_slist_sort (l2
, compare_func
),
286 #endif /* __jack_jslist_h__ */