add isl_union_map_is_bijective
[isl.git] / isl_list.c
blobdb2a608495602d9aa9a9fe67a9652097ae6f33ba
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #include <isl/list.h>
11 #include <isl/set.h>
13 struct isl_basic_set_list *isl_basic_set_list_alloc(struct isl_ctx *ctx, int n)
15 struct isl_basic_set_list *list;
17 isl_assert(ctx, n >= 0, return NULL);
18 list = isl_alloc(ctx, struct isl_basic_set_list,
19 sizeof(struct isl_basic_set_list) +
20 (n - 1) * sizeof(struct isl_basic_set *));
21 if (!list)
22 return NULL;
24 list->ctx = ctx;
25 isl_ctx_ref(ctx);
26 list->ref = 1;
27 list->size = n;
28 list->n = 0;
29 return list;
32 struct isl_basic_set_list *isl_basic_set_list_add(
33 struct isl_basic_set_list *list,
34 struct isl_basic_set *bset)
36 if (!list || !bset)
37 goto error;
38 isl_assert(list->ctx, list->n < list->size, goto error);
39 list->p[list->n] = bset;
40 list->n++;
41 return list;
42 error:
43 isl_basic_set_free(bset);
44 isl_basic_set_list_free(list);
45 return NULL;
48 void isl_basic_set_list_free(struct isl_basic_set_list *list)
50 int i;
52 if (!list)
53 return;
55 if (--list->ref > 0)
56 return;
58 isl_ctx_deref(list->ctx);
59 for (i = 0; i < list->n; ++i)
60 isl_basic_set_free(list->p[i]);
61 free(list);