TaPAS  0.2
ccl-list.h
Go to the documentation of this file.
1 /*
2  * ccl-list.h -- A generic list encoded with a simple chaining.
3  *
4  * This file is a part of the C Common Library (CCL) project.
5  *
6  * Copyright (C) 2010 CNRS UMR 5800 & Université Bordeaux I (see AUTHORS file).
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the AltaRica Public License that comes with this
10  * package.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  */
16 
21 #ifndef __CCL_LIST_H__
22 # define __CCL_LIST_H__
23 
24 # include <ccl/ccl-assert.h>
25 # include <ccl/ccl-protos.h>
26 # include <ccl/ccl-iterator.h>
27 
28 BEGIN_C_DECLS
29 
33 typedef struct ccl_list_st ccl_list;
34 
42 typedef struct ccl_pair_st ccl_pair;
43 
44 # ifndef IN_DOXYGEN_DOC
45 struct ccl_list_st {
46  int size;
47  ccl_pair *first;
48  ccl_pair **last;
49 };
50 
51 struct ccl_pair_st {
52  void *car;
53  ccl_pair *cdr;
54 };
55 # endif
56 
60 # define FIRST(l) ((l)->first)
61 
65 # define CAR(p) ((p)->car)
66 
70 # define CDR(p) ((p)->cdr)
71 
75 # define CADR(p) (CAR (CDR (p)))
76 
80 # define CDDR(p) (CDR (CDR (p)))
81 
85 # define CADDR(p) (CAR (CDDR (p)))
86 
90 # define CDDDR(p) (CDR (CDDR (p)))
91 
95 # define CADDDR(p) (CAR (CDDDR (p)))
96 
100 # define CDDDDR(p) (CDR (CDDDR (p)))
101 
105 # define CADDDDR(p) (CAR (CDDDDR (p)))
106 
110 # define CDDDDDR(p) (CDR (CDDDDR (p)))
111 
112 # define CCL_LIST_FOREACH(p,l) for ((p)=FIRST(l); (p); (p) = CDR (p))
113 
118 extern ccl_list *
119 ccl_list_create (void);
120 
131 extern void
133 
145 extern void
147 
159 extern void
161 
168 # define ccl_list_get_size(l) (ccl_pre ((l) != NULL), (l)->size)
169 
176 # define ccl_list_get_length(l) ccl_list_get_size(l)
177 
184 # define ccl_list_is_empty(l) (ccl_list_get_size (l) ==0)
185 
196 extern void
197 ccl_list_add (ccl_list *l, void *obj);
198 
207 extern int
208 ccl_list_has (const ccl_list *l, void *obj);
209 
219 extern void
220 ccl_list_put_first (ccl_list *l, void *obj);
221 
232 extern void *
234 
243 extern void
245 
246 extern void
247 ccl_list_sort_with_data (ccl_list *l, ccl_compare_with_data_func *cmp,
248  void *data);
249 
266 extern int
267 ccl_list_insert (ccl_list *l, void *obj, ccl_compare_func *cmp);
268 
269 extern void
270 ccl_list_insert_before (ccl_list *l, void *obj, void *inserted);
271 
272 extern void
273 ccl_list_insert_after (ccl_list *l, void *obj, void *inserted);
274 
287 extern int
288 ccl_list_equals (const ccl_list *l1, const ccl_list *l2);
289 
300 extern ccl_list *
301 ccl_list_dup (const ccl_list *l);
302 
316 extern ccl_list *
318 
326 extern void *
327 ccl_list_get_at (ccl_list *l, int index);
328 
339 extern void
340 ccl_list_remove (ccl_list *l, void *p);
341 
342 extern void
343 ccl_list_remove_filtered (ccl_list *l, int (*filter)(void *p, void *data),
344  void *filter_data, ccl_delete_proc *del);
345 
353 extern void
354 ccl_list_sub (ccl_list *l1, const ccl_list *l2);
355 
363 extern void
364 ccl_list_append (ccl_list *l1, const ccl_list *l2);
365 
366 extern void
367 ccl_list_deep_append (ccl_list *l1, const ccl_list *l2,
368  ccl_duplicate_func *dup);
369 
387 extern int
388 ccl_list_get_index (const ccl_list *l, void *ptr, ccl_compare_func *cmp);
389 
404 extern int
405 ccl_list_compare (const ccl_list *l1, const ccl_list *l2,
406  ccl_compare_func *cmp);
407 
417 extern unsigned int
418 ccl_list_hash (const ccl_list *l);
419 
432 extern unsigned int
434 
447 extern void **
448 ccl_list_to_array (const ccl_list *l, int *p_size);
449 
450 
451 extern ccl_pointer_iterator *
452 ccl_list_get_iterator (ccl_list *l, ccl_duplicate_func *dup,
453  ccl_delete_proc *del);
454 
455 extern ccl_list *
456 ccl_list_create_from_iterator (ccl_pointer_iterator *i);
457 
458 extern void
459 ccl_list_map (const ccl_list *l, ccl_map_proc *map, void *data);
460 
461 END_C_DECLS
462 
463 #endif /* ! __CCL_LIST_H__ */
int ccl_list_get_index(const ccl_list *l, void *ptr, ccl_compare_func *cmp)
Returns the position of ptr in the list l.
void ccl_list_delete(ccl_list *l)
Deletes the list l.
Frequently used prototypes of generic functions.
int ccl_list_compare(const ccl_list *l1, const ccl_list *l2, ccl_compare_func *cmp)
Compares the two lists l1 and l2 with the lexicographical order.
ccl_list * ccl_list_deep_dup(const ccl_list *l, ccl_duplicate_func *dup)
Duplicates the list l and stored objects.
A generic iterator interface.
ccl_list * ccl_list_dup(const ccl_list *l)
Duplicates the list l.
unsigned int ccl_list_hash(const ccl_list *l)
Computes a hashed value for the list l.
void ccl_list_remove(ccl_list *l, void *p)
Removes the object p from the list l.
unsigned int ccl_list_hash_all(const ccl_list *l, ccl_hash_func *h)
Computes a hashed value for the list l.
void ccl_list_clear(ccl_list *l, ccl_delete_proc *del)
Makes empty the list l.
int ccl_compare_func(const void *ptr1, const void *ptr2)
Prototype of functions used to order two objects pointed respectively by ptr1 and ptr2...
Definition: ccl-protos.h:73
void * ccl_list_take_first(ccl_list *l)
Removes the first object of the list l.
struct ccl_pair_st ccl_pair
Type of a cell of a ccl_list.
Definition: ccl-list.h:42
struct ccl_list_st ccl_list
Type of a generic list.
Definition: ccl-list.h:33
void ccl_delete_proc(void *ptr)
Prototype of procedures used to release the resources allocated to the object pointed by ptr...
Definition: ccl-protos.h:44
int ccl_list_equals(const ccl_list *l1, const ccl_list *l2)
Checks if l1 and l2 are equals.
void ccl_list_clear_and_delete(ccl_list *l, ccl_delete_proc *del)
Deletes the list l and stored objects.
void ccl_list_add(ccl_list *l, void *obj)
Adds an object obj at the end of the list l.
ccl_list * ccl_list_create(void)
Creates a new list.
void * ccl_list_get_at(ccl_list *l, int index)
Returns the object at the postion index.
void ccl_list_put_first(ccl_list *l, void *obj)
Adds an object obj at the beginning of the list l.
void * ccl_duplicate_func(void *ptr)
Prototype of functions used to duplicate an object pointed by ptr.
Definition: ccl-protos.h:89
void ccl_list_append(ccl_list *l1, const ccl_list *l2)
append l2 to l1
Macros allowing to set assertions into the code.
int ccl_list_insert(ccl_list *l, void *obj, ccl_compare_func *cmp)
Inserts the object obj into the ordered list l.
void ** ccl_list_to_array(const ccl_list *l, int *p_size)
Return a newly allocated array containing all elements of l.
int ccl_list_has(const ccl_list *l, void *obj)
Checks if the object obj belongs to l.
void ccl_list_sub(ccl_list *l1, const ccl_list *l2)
Removes the objects of l2 from l1.
unsigned int ccl_hash_func(const void *ptr)
Prototype of functions used to compute a hashed value from an abstract object pointed by ptr...
Definition: ccl-protos.h:32
void ccl_list_sort(ccl_list *l, ccl_compare_func *cmp)
(Quick-)Sort the list l using the comparison function cmp. If cmp == CCL_DEFAULT_COMPARE_FUNC, addresses of objects are compared.