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 
116 extern ccl_list *
117 ccl_list_create (void);
118 
129 extern void
131 
143 extern void
145 
157 extern void
159 
166 # define ccl_list_get_size(l) (ccl_pre ((l) != NULL), (l)->size)
167 
174 # define ccl_list_get_length(l) ccl_list_get_size(l)
175 
182 # define ccl_list_is_empty(l) (ccl_list_get_size (l) ==0)
183 
194 extern void
195 ccl_list_add (ccl_list *l, void *obj);
196 
205 extern int
206 ccl_list_has (const ccl_list *l, void *obj);
207 
217 extern void
218 ccl_list_put_first (ccl_list *l, void *obj);
219 
230 extern void *
232 
241 extern void
243 
244 typedef int ccl_compare_with_data_func (const void *o1, const void *o2,
245  const void *data);
246 
247 #define CCL_DEFAULT_COMPARE_WITH_DATA_FUNC NULL
248 
249 extern void
250 ccl_list_sort_with_data (ccl_list *l, ccl_compare_with_data_func *cmp,
251  const void *data);
252 
269 extern int
270 ccl_list_insert (ccl_list *l, void *obj, ccl_compare_func *cmp);
271 
272 extern void
273 ccl_list_insert_before (ccl_list *l, void *obj, void *inserted);
274 
275 extern void
276 ccl_list_insert_after (ccl_list *l, void *obj, void *inserted);
277 
290 extern int
291 ccl_list_equals (const ccl_list *l1, const ccl_list *l2);
292 
303 extern ccl_list *
304 ccl_list_dup (const ccl_list *l);
305 
319 extern ccl_list *
321 
329 extern void *
330 ccl_list_get_at (ccl_list *l, int index);
331 
342 extern void
343 ccl_list_remove (ccl_list *l, void *p);
344 
352 extern void
353 ccl_list_sub (ccl_list *l1, const ccl_list *l2);
354 
362 extern void
363 ccl_list_append (ccl_list *l1, const ccl_list *l2);
364 
365 extern void
366 ccl_list_deep_append (ccl_list *l1, const ccl_list *l2,
367  ccl_duplicate_func *dup);
368 
386 extern int
387 ccl_list_get_index (const ccl_list *l, void *ptr, ccl_compare_func *cmp);
388 
403 extern int
404 ccl_list_compare (const ccl_list *l1, const ccl_list *l2,
405  ccl_compare_func *cmp);
406 
416 extern unsigned int
417 ccl_list_hash (const ccl_list *l);
418 
431 extern unsigned int
433 
446 extern void **
447 ccl_list_to_array (const ccl_list *l, int *p_size);
448 
449 
450 extern ccl_pointer_iterator *
451 ccl_list_get_iterator (ccl_list *l, ccl_duplicate_func *dup,
452  ccl_delete_proc *del);
453 
454 extern ccl_list *
455 ccl_list_create_from_iterator (ccl_pointer_iterator *i);
456 
457 END_C_DECLS
458 
459 #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:84
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.