add isl_*_list_drop
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 8 Aug 2012 08:14:33 +0000 (10:14 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 10 Aug 2012 07:40:36 +0000 (09:40 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/list.h
isl_list_templ.c
isl_test.c

index 2ecb82e..832b92c 100644 (file)
@@ -2899,6 +2899,9 @@ Lists can be created, copied, modified and freed using the following functions.
        __isl_give isl_set_list *isl_set_list_add(
                __isl_take isl_set_list *list,
                __isl_take isl_set *el);
+       __isl_give isl_set_list *isl_set_list_drop(
+               __isl_take isl_set_list *list,
+               unsigned first, unsigned n);
        __isl_give isl_set_list *isl_set_list_set_set(
                __isl_take isl_set_list *list, int index,
                __isl_take isl_set *set);
index ed295ee..7f22b13 100644 (file)
@@ -31,6 +31,8 @@ void *isl_##EL##_list_free(__isl_take isl_##EL##_list *list);         \
 __isl_give isl_##EL##_list *isl_##EL##_list_add(                       \
        __isl_take isl_##EL##_list *list,                               \
        __isl_take struct isl_##EL *el);                                \
+__isl_give isl_##EL##_list *isl_##EL##_list_drop(                      \
+       __isl_take isl_##EL##_list *list, unsigned first, unsigned n);  \
 __isl_give isl_##EL##_list *isl_##EL##_list_concat(                    \
        __isl_take isl_##EL##_list *list1,                              \
        __isl_take isl_##EL##_list *list2);                             \
index 3677d10..ec5391b 100644 (file)
@@ -134,6 +134,31 @@ error:
        return NULL;
 }
 
+/* Remove the "n" elements starting at "first" from "list".
+ */
+__isl_give LIST(EL) *FN(LIST(EL),drop)(__isl_take LIST(EL) *list,
+       unsigned first, unsigned n)
+{
+       int i;
+
+       if (!list)
+               return NULL;
+       if (first + n > list->n || first + n < first)
+               isl_die(list->ctx, isl_error_invalid,
+                       "index out of bounds", return FN(LIST(EL),free)(list));
+       if (n == 0)
+               return list;
+       list = FN(LIST(EL),cow)(list);
+       if (!list)
+               return NULL;
+       for (i = 0; i < n; ++i)
+               FN(EL,free)(list->p[first + i]);
+       for (i = first; i + n < list->n; ++i)
+               list->p[i] = list->p[i + n];
+       list->n -= n;
+       return list;
+}
+
 void *FN(LIST(EL),free)(__isl_take LIST(EL) *list)
 {
        int i;
index 45f8c97..33645c0 100644 (file)
@@ -3039,10 +3039,54 @@ int test_align_parameters(isl_ctx *ctx)
        return 0;
 }
 
+static int test_list(isl_ctx *ctx)
+{
+       isl_id *a, *b, *c, *d, *id;
+       isl_id_list *list;
+       int ok;
+
+       a = isl_id_alloc(ctx, "a", NULL);
+       b = isl_id_alloc(ctx, "b", NULL);
+       c = isl_id_alloc(ctx, "c", NULL);
+       d = isl_id_alloc(ctx, "d", NULL);
+
+       list = isl_id_list_alloc(ctx, 4);
+       list = isl_id_list_add(list, a);
+       list = isl_id_list_add(list, b);
+       list = isl_id_list_add(list, c);
+       list = isl_id_list_add(list, d);
+       list = isl_id_list_drop(list, 1, 1);
+
+       if (isl_id_list_n_id(list) != 3) {
+               isl_id_list_free(list);
+               isl_die(ctx, isl_error_unknown,
+                       "unexpected number of elements in list", return -1);
+       }
+
+       id = isl_id_list_get_id(list, 0);
+       ok = id == a;
+       isl_id_free(id);
+       id = isl_id_list_get_id(list, 1);
+       ok = ok && id == c;
+       isl_id_free(id);
+       id = isl_id_list_get_id(list, 2);
+       ok = ok && id == d;
+       isl_id_free(id);
+
+       isl_id_list_free(list);
+
+       if (!ok)
+               isl_die(ctx, isl_error_unknown,
+                       "unexpected elements in list", return -1);
+
+       return 0;
+}
+
 struct {
        const char *name;
        int (*fn)(isl_ctx *ctx);
 } tests [] = {
+       { "list", &test_list },
        { "align parameters", &test_align_parameters },
        { "eliminate", &test_eliminate },
        { "div", &test_div },