osl_relation_remove_column already updates the nb_columns
[clay.git] / source / list.c
blob587e130374311a7f245d5173440fe89e8f2198c9
2 /*--------------------------------------------------------------------+
3 | Clay |
4 |--------------------------------------------------------------------|
5 | list.c |
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 |
16 | |
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. |
21 | |
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. |
26 | |
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 |
31 | |
32 | Clay, the Chunky Loop Alteration wizardrY |
33 | Written by Joel Poudroux, joel.poudroux@u-psud.fr |
34 +--------------------------------------------------------------------------*/
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <clay/macros.h>
40 #include <clay/list.h>
43 clay_list_p clay_list_malloc() {
44 clay_list_p l;
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);
47 l->size = 0;
48 l->available = CLAY_LIST_INIT_SIZE;
49 return l;
53 void clay_list_add(clay_list_p l, clay_array_p a) {
54 if (l->size >= l->available) {
55 l->available *= 2;
56 CLAY_realloc(l->data, clay_array_p*, sizeof(clay_array_p) * l->available);
59 l->data[l->size] = a;
60 (l->size)++;
64 void clay_list_free(clay_list_p l) {
65 if (l) {
66 int i;
67 for (i = 0 ; i < l->size ; i++)
68 clay_array_free(l->data[i]);
69 free(l->data);
70 free(l);
75 void clay_list_print(FILE *out, clay_list_p l) {
76 if (l == NULL) {
77 fprintf(out, "NULL\n");
78 return;
80 int i;
81 fprintf(out, "{");
82 for (i = 0 ; i < l->size-1 ; i++) {
83 clay_array_print(out, l->data[i], 0);
84 fprintf(out, ",");
86 if(l->size > 0)
87 clay_array_print(out, l->data[i], 0);
88 fprintf(out, "}\n");
92 void clay_list_clear(clay_list_p l) {
93 int i;
94 for (i = 0 ; i < l->size ; i++) {
95 l->data[i]->size = 0;
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;
103 int i, j;
104 for (i = 0 ; i < l->size ; i++) {
105 tmp = clay_array_malloc();
106 orig = l->data[i];
108 for (j = 0 ; j < orig->size ; j++)
109 clay_array_add(tmp, orig->data[j]);
111 clay_list_add(newl, tmp);
113 return newl;