isl_convex_hull.c: use isl_seq_get_hash instead of isl_seq_hash
[isl.git] / isl_list.c
blobcfbff6383d1db08d1afb8ba0635a67e8d4773a3a
1 #include "isl_list.h"
3 struct isl_basic_set_list *isl_basic_set_list_alloc(struct isl_ctx *ctx, int n)
5 struct isl_basic_set_list *list;
7 isl_assert(ctx, n >= 0, return NULL);
8 list = isl_alloc(ctx, struct isl_basic_set_list,
9 sizeof(struct isl_basic_set_list) +
10 (n - 1) * sizeof(struct isl_basic_set *));
11 if (!list)
12 return NULL;
14 list->ctx = ctx;
15 isl_ctx_ref(ctx);
16 list->ref = 1;
17 list->size = n;
18 list->n = 0;
19 return list;
22 struct isl_basic_set_list *isl_basic_set_list_add(
23 struct isl_basic_set_list *list,
24 struct isl_basic_set *bset)
26 if (!list || !bset)
27 goto error;
28 isl_assert(list->ctx, list->n < list->size, goto error);
29 list->p[list->n] = bset;
30 list->n++;
31 return list;
32 error:
33 isl_basic_set_free(bset);
34 isl_basic_set_list_free(list);
35 return NULL;
38 void isl_basic_set_list_free(struct isl_basic_set_list *list)
40 int i;
42 if (!list)
43 return;
45 if (--list->ref > 0)
46 return;
48 isl_ctx_deref(list->ctx);
49 for (i = 0; i < list->n; ++i)
50 isl_basic_set_free(list->p[i]);
51 free(list);