From c7619f4cd7c7cbd9c7fe5688c6cd7c7853a52dec Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 12 Sep 2012 12:30:46 +0200 Subject: [PATCH] add isl_set_is_disjoint Signed-off-by: Sven Verdoolaege --- doc/user.pod | 4 ++++ include/isl/map.h | 2 ++ include/isl/set.h | 2 ++ isl_map_simplify.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/doc/user.pod b/doc/user.pod index b637d82e..a2892a9a 100644 --- a/doc/user.pod +++ b/doc/user.pod @@ -1903,6 +1903,10 @@ Check whether the range of the (basic) relation is a wrapped relation. int isl_set_plain_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2); + int isl_set_is_disjoint(__isl_keep isl_set *set1, + __isl_keep isl_set *set2); + int isl_map_is_disjoint(__isl_keep isl_map *map1, + __isl_keep isl_map *map2); =item * Subset diff --git a/include/isl/map.h b/include/isl/map.h index 5aee7b2f..1b7d413d 100644 --- a/include/isl/map.h +++ b/include/isl/map.h @@ -515,6 +515,8 @@ __isl_export int isl_map_is_strict_subset(__isl_keep isl_map *map1, __isl_keep isl_map *map2); __isl_export int isl_map_is_equal(__isl_keep isl_map *map1, __isl_keep isl_map *map2); +__isl_export +int isl_map_is_disjoint(__isl_keep isl_map *map1, __isl_keep isl_map *map2); int isl_basic_map_is_single_valued(__isl_keep isl_basic_map *bmap); int isl_map_plain_is_single_valued(__isl_keep isl_map *map); __isl_export diff --git a/include/isl/set.h b/include/isl/set.h index 64d502e0..bf2440ea 100644 --- a/include/isl/set.h +++ b/include/isl/set.h @@ -366,6 +366,8 @@ __isl_export int isl_set_is_strict_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2); __isl_export int isl_set_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2); +__isl_export +int isl_set_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2); int isl_set_is_singleton(__isl_keep isl_set *set); int isl_set_is_box(__isl_keep isl_set *set); int isl_set_has_equal_space(__isl_keep isl_set *set1, __isl_keep isl_set *set2); diff --git a/isl_map_simplify.c b/isl_map_simplify.c index 2582d08f..2a366529 100644 --- a/isl_map_simplify.c +++ b/isl_map_simplify.c @@ -2199,6 +2199,46 @@ int isl_map_plain_is_disjoint(__isl_keep isl_map *map1, return 1; } +/* Are "map1" and "map2" disjoint? + * + * They are disjoint if they are "obviously disjoint" or if one of them + * is empty. Otherwise, they are not disjoint if one of them is universal. + * If none of these cases apply, we compute the intersection and see if + * the result is empty. + */ +int isl_map_is_disjoint(__isl_keep isl_map *map1, __isl_keep isl_map *map2) +{ + int disjoint; + int intersect; + isl_map *test; + + disjoint = isl_map_plain_is_disjoint(map1, map2); + if (disjoint < 0 || disjoint) + return disjoint; + + disjoint = isl_map_is_empty(map1); + if (disjoint < 0 || disjoint) + return disjoint; + + disjoint = isl_map_is_empty(map2); + if (disjoint < 0 || disjoint) + return disjoint; + + intersect = isl_map_plain_is_universe(map1); + if (intersect < 0 || intersect) + return intersect < 0 ? -1 : 0; + + intersect = isl_map_plain_is_universe(map2); + if (intersect < 0 || intersect) + return intersect < 0 ? -1 : 0; + + test = isl_map_intersect(isl_map_copy(map1), isl_map_copy(map2)); + disjoint = isl_map_is_empty(test); + isl_map_free(test); + + return disjoint; +} + int isl_set_plain_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2) { @@ -2206,6 +2246,13 @@ int isl_set_plain_is_disjoint(__isl_keep isl_set *set1, (struct isl_map *)set2); } +/* Are "set1" and "set2" disjoint? + */ +int isl_set_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2) +{ + return isl_map_is_disjoint(set1, set2); +} + int isl_set_fast_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2) { return isl_set_plain_is_disjoint(set1, set2); -- 2.11.4.GIT