add isl_*_list_every
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Sun, 30 Jun 2019 08:09:14 +0000 (30 10:09 +0200)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Thu, 28 May 2020 19:31:06 +0000 (28 21:31 +0200)
Similarly to isl_union_map_every_map and isl_union_set_every_set,
these functions check whether the callback functions returns true
on each element.

This will be used to clean up list_constant_is_negative
in an upcoming commit, but can be more generally useful.

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
doc/user.pod
include/isl/list.h
isl_list_templ.c

index faf5ce0..8928442 100644 (file)
@@ -8743,6 +8743,10 @@ Lists can be inspected using the following functions.
        isl_stat isl_set_list_foreach(__isl_keep isl_set_list *list,
                isl_stat (*fn)(__isl_take isl_set *el, void *user),
                void *user);
+       isl_bool isl_set_list_every(__isl_keep isl_set_list *list,
+               isl_bool (*test)(__isl_take isl_set *el,
+                       void *user),
+               void *user);
        isl_stat isl_set_list_foreach_scc(
                __isl_keep isl_set_list *list,
                isl_bool (*follows)(__isl_keep isl_set *a,
index b5ffe49..337721c 100644 (file)
@@ -72,6 +72,9 @@ EXPORT                                                                        \
 isl_stat isl_##EL##_list_foreach(__isl_keep isl_##EL##_list *list,     \
        isl_stat (*fn)(__isl_take isl_##EL *el, void *user),            \
        void *user);                                                    \
+isl_bool isl_##EL##_list_every(__isl_keep isl_##EL##_list *list,       \
+       isl_bool (*test)(__isl_keep isl_##EL *el, void *user),          \
+       void *user);                                                    \
 __isl_give isl_##EL##_list *isl_##EL##_list_map(                       \
        __isl_take isl_##EL##_list *list,                               \
        __isl_give isl_##EL * (*fn)(__isl_take isl_##EL *el,            \
index 7a3c424..f398ba9 100644 (file)
@@ -393,6 +393,27 @@ isl_stat FN(LIST(EL),foreach)(__isl_keep LIST(EL) *list,
        return isl_stat_ok;
 }
 
+/* Does "test" succeed on every element of "list"?
+ */
+isl_bool FN(LIST(EL),every)(__isl_keep LIST(EL) *list,
+       isl_bool (*test)(__isl_keep EL *el, void *user), void *user)
+{
+       int i;
+
+       if (!list)
+               return isl_bool_error;
+
+       for (i = 0; i < list->n; ++i) {
+               isl_bool r;
+
+               r = test(list->p[i], user);
+               if (r < 0 || !r)
+                       return r;
+       }
+
+       return isl_bool_true;
+}
+
 /* Replace each element in "list" by the result of calling "fn"
  * on the element.
  */