add isl_*_list_set_*
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 29 Feb 2012 16:30:38 +0000 (17:30 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 2 Aug 2012 10:20:08 +0000 (12:20 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/list.h
isl_list_templ.c

index 2202066..74cb4ce 100644 (file)
@@ -2814,7 +2814,7 @@ returning a basic set or relation.
 Lists are defined over several element types, including
 C<isl_aff>, C<isl_pw_aff>, C<isl_basic_set> and C<isl_set>.
 Here we take lists of C<isl_set>s as an example.
-Lists can be created, copied and freed using the following functions.
+Lists can be created, copied, modified and freed using the following functions.
 
        #include <isl/list.h>
        __isl_give isl_set_list *isl_set_list_from_set(
@@ -2826,6 +2826,9 @@ Lists can be created, copied 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_set_set(
+               __isl_take isl_set_list *list, int index,
+               __isl_take isl_set *set);
        __isl_give isl_set_list *isl_set_list_concat(
                __isl_take isl_set_list *list1,
                __isl_take isl_set_list *list2);
index e0dbfed..d14df28 100644 (file)
@@ -37,6 +37,9 @@ __isl_give isl_##EL##_list *isl_##EL##_list_concat(                   \
 int isl_##EL##_list_n_##EL(__isl_keep isl_##EL##_list *list);          \
 __isl_give struct isl_##EL *isl_##EL##_list_get_##EL(                  \
        __isl_keep isl_##EL##_list *list, int index);                   \
+__isl_give struct isl_##EL##_list *isl_##EL##_list_set_##EL(           \
+       __isl_take struct isl_##EL##_list *list, int index,             \
+       __isl_take struct isl_##EL *el);                                \
 int isl_##EL##_list_foreach(__isl_keep isl_##EL##_list *list,          \
        int (*fn)(__isl_take struct isl_##EL *el, void *user),          \
        void *user);                                                    \
index 9aa4351..887a92f 100644 (file)
@@ -70,6 +70,17 @@ __isl_give LIST(EL) *FN(LIST(EL),dup)(__isl_keep LIST(EL) *list)
        return dup;
 }
 
+__isl_give LIST(EL) *FN(LIST(EL),cow)(__isl_take LIST(EL) *list)
+{
+       if (!list)
+               return NULL;
+
+       if (list->ref == 1)
+               return list;
+       list->ref--;
+       return FN(LIST(EL),dup)(list);
+}
+
 __isl_give LIST(EL) *FN(LIST(EL),add)(__isl_take LIST(EL) *list,
        __isl_take struct EL *el)
 {
@@ -118,6 +129,32 @@ __isl_give EL *FN(FN(LIST(EL),get),BASE)(__isl_keep LIST(EL) *list, int index)
        return FN(EL,copy)(list->p[index]);
 }
 
+/* Replace the element at position "index" in "list" by "el".
+ */
+__isl_give LIST(EL) *FN(FN(LIST(EL),set),BASE)(__isl_take LIST(EL) *list,
+       int index, __isl_take EL *el)
+{
+       if (!list || !el)
+               goto error;
+       if (index < 0 || index >= list->n)
+               isl_die(list->ctx, isl_error_invalid,
+                       "index out of bounds", goto error);
+       if (list->p[index] == el) {
+               FN(EL,free)(el);
+               return list;
+       }
+       list = FN(LIST(EL),cow)(list);
+       if (!list)
+               goto error;
+       FN(EL,free)(list->p[index]);
+       list->p[index] = el;
+       return list;
+error:
+       FN(EL,free)(el);
+       FN(LIST(EL),free)(list);
+       return NULL;
+}
+
 int FN(LIST(EL),foreach)(__isl_keep LIST(EL) *list,
        int (*fn)(__isl_take EL *el, void *user), void *user)
 {