From 85c1778d7784ad02d34e48d57f39f360d0c28e6f Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 24 Aug 2008 19:33:36 +0200 Subject: [PATCH] add isl_map_remove_empty_parts --- isl_map.c | 30 ++++++++++++++++++++++++++++++ isl_map_private.h | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/isl_map.c b/isl_map.c index a0b5105..38308ae 100644 --- a/isl_map.c +++ b/isl_map.c @@ -3040,3 +3040,33 @@ error: isl_map_free(ctx, map); return NULL; } + +/* There is no need to cow as removing empty parts doesn't change + * the meaning of the set. + */ +struct isl_map *isl_map_remove_empty_parts(struct isl_ctx *ctx, + struct isl_map *map) +{ + int i; + + if (!map) + return NULL; + + for (i = map->n-1; i >= 0; --i) { + if (!F_ISSET(map->p[i], ISL_BASIC_MAP_EMPTY)) + continue; + isl_basic_map_free(ctx, map->p[i]); + if (i != map->n-1) + map->p[i] = map->p[map->n-1]; + map->n--; + } + + return map; +} + +struct isl_set *isl_set_remove_empty_parts(struct isl_ctx *ctx, + struct isl_set *set) +{ + return (struct isl_set *) + isl_map_remove_empty_parts(ctx, (struct isl_map *)set); +} diff --git a/isl_map_private.h b/isl_map_private.h index f57763f..2a62487 100644 --- a/isl_map_private.h +++ b/isl_map_private.h @@ -42,3 +42,8 @@ struct isl_basic_map *isl_basic_map_gauss(struct isl_ctx *ctx, struct isl_basic_map *bmap, int *progress); struct isl_basic_set *isl_basic_set_gauss(struct isl_ctx *ctx, struct isl_basic_set *bset, int *progress); + +struct isl_map *isl_map_remove_empty_parts(struct isl_ctx *ctx, + struct isl_map *map); +struct isl_set *isl_set_remove_empty_parts(struct isl_ctx *ctx, + struct isl_set *set); -- 2.7.4