uint32_t hash;
struct isl_hash_table_entry *entry;
- if (isl_map_fast_is_empty(map)) {
+ if (isl_map_plain_is_empty(map)) {
isl_map_free(map);
return umap;
}
&call_on_copy, &data);
}
+static int copy_map(void **entry, void *user)
+{
+ isl_map *map = *entry;
+ isl_map **map_p = user;
+
+ *map_p = isl_map_copy(map);
+
+ return -1;
+}
+
+__isl_give isl_map *isl_union_map_copy_map(__isl_keep isl_union_map *umap)
+{
+ isl_map *map = NULL;
+
+ if (!umap || umap->table.n == 0)
+ return NULL;
+
+ isl_hash_table_foreach(umap->dim->ctx, &umap->table, ©_map, &map);
+
+ return map;
+}
+
+__isl_give isl_set *isl_union_set_copy_set(__isl_keep isl_union_set *uset)
+{
+ return isl_union_map_copy_map(uset);
+}
+
__isl_give isl_map *isl_union_map_extract_map(__isl_keep isl_union_map *umap,
__isl_take isl_dim *dim)
{
return (isl_set *)isl_union_map_extract_map(uset, dim);
}
+/* Check if umap contains a map in the given space.
+ */
+__isl_give int isl_union_map_contains(__isl_keep isl_union_map *umap,
+ __isl_keep isl_dim *dim)
+{
+ uint32_t hash;
+ struct isl_hash_table_entry *entry;
+
+ if (!umap || !dim)
+ return -1;
+
+ hash = isl_dim_get_hash(dim);
+ entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash,
+ &has_dim, dim, 0);
+ return !!entry;
+}
+
+__isl_give int isl_union_set_contains(__isl_keep isl_union_set *uset,
+ __isl_keep isl_dim *dim)
+{
+ return isl_union_map_contains(uset, dim);
+}
+
int isl_union_set_foreach_set(__isl_keep isl_union_set *uset,
int (*fn)(__isl_take isl_set *set, void *user), void *user)
{
*sample = isl_map_sample(isl_map_copy(map));
if (!*sample)
return -1;
- if (!isl_basic_map_fast_is_empty(*sample))
+ if (!isl_basic_map_plain_is_empty(*sample))
return -1;
return 0;
}
return (isl_basic_set *)isl_union_map_sample(uset);
}
-static int empty_entry(void **entry, void *user)
+struct isl_forall_data {
+ int res;
+ int (*fn)(__isl_keep isl_map *map);
+};
+
+static int forall_entry(void **entry, void *user)
{
- int *empty = user;
+ struct isl_forall_data *data = user;
isl_map *map = *entry;
- if (isl_map_is_empty(map))
- return 0;
+ data->res = data->fn(map);
+ if (data->res < 0)
+ return -1;
- *empty = 0;
+ if (!data->res)
+ return -1;
- return -1;
+ return 0;
}
-__isl_give int isl_union_map_is_empty(__isl_keep isl_union_map *umap)
+static int union_map_forall(__isl_keep isl_union_map *umap,
+ int (*fn)(__isl_keep isl_map *map))
{
- int empty = 1;
+ struct isl_forall_data data = { 1, fn };
if (!umap)
return -1;
if (isl_hash_table_foreach(umap->dim->ctx, &umap->table,
- &empty_entry, &empty) < 0 && empty)
+ &forall_entry, &data) < 0 && data.res)
return -1;
- return empty;
+ return data.res;
+}
+
+int isl_union_map_is_empty(__isl_keep isl_union_map *umap)
+{
+ return union_map_forall(umap, &isl_map_is_empty);
}
int isl_union_set_is_empty(__isl_keep isl_union_set *uset)
{
return isl_union_map_is_empty(uset);
}
+
+static int is_subset_of_identity(__isl_keep isl_map *map)
+{
+ int is_subset;
+ isl_dim *dim;
+ isl_map *id;
+
+ if (!map)
+ return -1;
+
+ if (!isl_dim_tuple_match(map->dim, isl_dim_in, map->dim, isl_dim_out))
+ return 0;
+
+ dim = isl_map_get_dim(map);
+ id = isl_map_identity(dim);
+
+ is_subset = isl_map_is_subset(map, id);
+
+ isl_map_free(id);
+
+ return is_subset;
+}
+
+/* Check if the given map is single-valued.
+ * We simply compute
+ *
+ * M \circ M^-1
+ *
+ * and check if the result is a subset of the identity mapping.
+ */
+int isl_union_map_is_single_valued(__isl_keep isl_union_map *umap)
+{
+ isl_union_map *test;
+ int sv;
+
+ if (isl_union_map_n_map(umap) == 1) {
+ isl_map *map = isl_union_map_copy_map(umap);
+ sv = isl_map_is_single_valued(map);
+ isl_map_free(map);
+ return sv;
+ }
+
+ test = isl_union_map_reverse(isl_union_map_copy(umap));
+ test = isl_union_map_apply_range(test, isl_union_map_copy(umap));
+
+ sv = union_map_forall(test, &is_subset_of_identity);
+
+ isl_union_map_free(test);
+
+ return sv;
+}
+
+int isl_union_map_is_injective(__isl_keep isl_union_map *umap)
+{
+ int in;
+
+ umap = isl_union_map_copy(umap);
+ umap = isl_union_map_reverse(umap);
+ in = isl_union_map_is_single_valued(umap);
+ isl_union_map_free(umap);
+
+ return in;
+}
+
+int isl_union_map_is_bijective(__isl_keep isl_union_map *umap)
+{
+ int sv;
+
+ sv = isl_union_map_is_single_valued(umap);
+ if (sv < 0 || !sv)
+ return sv;
+
+ return isl_union_map_is_injective(umap);
+}
+
+static int zip_entry(void **entry, void *user)
+{
+ isl_map *map = *entry;
+ isl_union_map **res = user;
+
+ if (!isl_map_can_zip(map))
+ return 0;
+
+ *res = isl_union_map_add_map(*res, isl_map_zip(isl_map_copy(map)));
+
+ return 0;
+}
+
+__isl_give isl_union_map *isl_union_map_zip(__isl_take isl_union_map *umap)
+{
+ return cond_un_op(umap, &zip_entry);
+}
+
+static int lift_entry(void **entry, void *user)
+{
+ isl_set *set = *entry;
+ isl_union_set **res = user;
+
+ *res = isl_union_set_add_set(*res, isl_set_lift(isl_set_copy(set)));
+
+ return 0;
+}
+
+__isl_give isl_union_set *isl_union_set_lift(__isl_take isl_union_set *uset)
+{
+ return cond_un_op(uset, &lift_entry);
+}
+
+static int coefficients_entry(void **entry, void *user)
+{
+ isl_set *set = *entry;
+ isl_union_set **res = user;
+
+ set = isl_set_copy(set);
+ set = isl_set_from_basic_set(isl_set_coefficients(set));
+ *res = isl_union_set_add_set(*res, set);
+
+ return 0;
+}
+
+__isl_give isl_union_set *isl_union_set_coefficients(
+ __isl_take isl_union_set *uset)
+{
+ isl_ctx *ctx;
+ isl_dim *dim;
+ isl_union_set *res;
+
+ if (!uset)
+ return NULL;
+
+ ctx = isl_union_set_get_ctx(uset);
+ dim = isl_dim_set_alloc(ctx, 0, 0);
+ res = isl_union_map_alloc(dim, uset->table.n);
+ if (isl_hash_table_foreach(uset->dim->ctx, &uset->table,
+ &coefficients_entry, &res) < 0)
+ goto error;
+
+ isl_union_set_free(uset);
+ return res;
+error:
+ isl_union_set_free(uset);
+ isl_union_set_free(res);
+ return NULL;
+}
+
+static int solutions_entry(void **entry, void *user)
+{
+ isl_set *set = *entry;
+ isl_union_set **res = user;
+
+ set = isl_set_copy(set);
+ set = isl_set_from_basic_set(isl_set_solutions(set));
+ if (!*res)
+ *res = isl_union_set_from_set(set);
+ else
+ *res = isl_union_set_add_set(*res, set);
+
+ if (!*res)
+ return -1;
+
+ return 0;
+}
+
+__isl_give isl_union_set *isl_union_set_solutions(
+ __isl_take isl_union_set *uset)
+{
+ isl_ctx *ctx;
+ isl_dim *dim;
+ isl_union_set *res = NULL;
+
+ if (!uset)
+ return NULL;
+
+ if (uset->table.n == 0) {
+ res = isl_union_set_empty(isl_union_set_get_dim(uset));
+ isl_union_set_free(uset);
+ return res;
+ }
+
+ if (isl_hash_table_foreach(uset->dim->ctx, &uset->table,
+ &solutions_entry, &res) < 0)
+ goto error;
+
+ isl_union_set_free(uset);
+ return res;
+error:
+ isl_union_set_free(uset);
+ isl_union_set_free(res);
+ return NULL;
+}