summaryrefslogtreecommitdiff
path: root/isl_list.c
blob: db2a608495602d9aa9a9fe67a9652097ae6f33ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Copyright 2008-2009 Katholieke Universiteit Leuven
 *
 * Use of this software is governed by the GNU LGPLv2.1 license
 *
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
 */

#include <isl/list.h>
#include <isl/set.h>

struct isl_basic_set_list *isl_basic_set_list_alloc(struct isl_ctx *ctx, int n)
{
	struct isl_basic_set_list *list;

	isl_assert(ctx, n >= 0, return NULL);
	list = isl_alloc(ctx, struct isl_basic_set_list,
			 sizeof(struct isl_basic_set_list) +
			 (n - 1) * sizeof(struct isl_basic_set *));
	if (!list)
		return NULL;

	list->ctx = ctx;
	isl_ctx_ref(ctx);
	list->ref = 1;
	list->size = n;
	list->n = 0;
	return list;
}

struct isl_basic_set_list *isl_basic_set_list_add(
	struct isl_basic_set_list *list,
	struct isl_basic_set *bset)
{
	if (!list || !bset)
		goto error;
	isl_assert(list->ctx, list->n < list->size, goto error);
	list->p[list->n] = bset;
	list->n++;
	return list;
error:
	isl_basic_set_free(bset);
	isl_basic_set_list_free(list);
	return NULL;
}

void isl_basic_set_list_free(struct isl_basic_set_list *list)
{
	int i;

	if (!list)
		return;

	if (--list->ref > 0)
		return;

	isl_ctx_deref(list->ctx);
	for (i = 0; i < list->n; ++i)
		isl_basic_set_free(list->p[i]);
	free(list);
}