2 /*--------------------------------------------------------------------+
4 |--------------------------------------------------------------------|
6 |--------------------------------------------------------------------|
7 | First version: 03/04/2012 |
8 +--------------------------------------------------------------------+
10 +--------------------------------------------------------------------------+
11 | / __)( ) /__\ ( \/ ) |
12 | ( (__ )(__ /(__)\ \ / Chunky Loop Alteration wizardrY |
13 | \___)(____)(__)(__)(__) |
14 +--------------------------------------------------------------------------+
15 | Copyright (C) 2012 University of Paris-Sud |
17 | This library is free software; you can redistribute it and/or modify it |
18 | under the terms of the GNU Lesser General Public License as published by |
19 | the Free Software Foundation; either version 2.1 of the License, or |
20 | (at your option) any later version. |
22 | This library is distributed in the hope that it will be useful but |
23 | WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
25 | General Public License for more details. |
27 | You should have received a copy of the GNU Lesser General Public License |
28 | along with this software; if not, write to the Free Software Foundation, |
29 | Inc., 51 Franklin Street, Fifth Floor, |
30 | Boston, MA 02110-1301 USA |
32 | Clay, the Chunky Loop Alteration wizardrY |
33 | Written by Joel Poudroux, joel.poudroux@u-psud.fr |
34 +--------------------------------------------------------------------------*/
39 #include <clay/macros.h>
40 #include <clay/list.h>
43 clay_list_p
clay_list_malloc() {
45 CLAY_malloc(l
, clay_list_p
, sizeof(clay_list_t
));
46 CLAY_malloc(l
->data
, clay_array_p
*, sizeof(clay_array_p
) * CLAY_LIST_INIT_SIZE
);
48 l
->available
= CLAY_LIST_INIT_SIZE
;
53 void clay_list_add(clay_list_p l
, clay_array_p a
) {
54 if (l
->size
>= l
->available
) {
56 CLAY_realloc(l
->data
, clay_array_p
*, sizeof(clay_array_p
) * l
->available
);
64 void clay_list_free(clay_list_p l
) {
67 for (i
= 0 ; i
< l
->size
; i
++)
68 clay_array_free(l
->data
[i
]);
75 void clay_list_print(FILE *out
, clay_list_p l
) {
77 fprintf(out
, "NULL\n");
82 for (i
= 0 ; i
< l
->size
-1 ; i
++) {
83 clay_array_print(out
, l
->data
[i
], 0);
87 clay_array_print(out
, l
->data
[i
], 0);
92 void clay_list_clear(clay_list_p l
) {
94 for (i
= 0 ; i
< l
->size
; i
++) {
100 clay_list_p
clay_list_clone(clay_list_p l
) {
101 clay_list_p newl
= clay_list_malloc();
102 clay_array_p tmp
, orig
;
104 for (i
= 0 ; i
< l
->size
; i
++) {
105 tmp
= clay_array_malloc();
108 for (j
= 0 ; j
< orig
->size
; j
++)
109 clay_array_add(tmp
, orig
->data
[j
]);
111 clay_list_add(newl
, tmp
);