From e4b14abb6299fe47d3a2c30621816bcb5d279759 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 9 Apr 2011 20:18:18 +0200 Subject: [PATCH] add isl_hmap_map_basic_set Signed-off-by: Sven Verdoolaege --- Makefile.am | 2 + isl_hmap_map_basic_set.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++ isl_hmap_map_basic_set.h | 26 ++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 isl_hmap_map_basic_set.c create mode 100644 isl_hmap_map_basic_set.h diff --git a/Makefile.am b/Makefile.am index c8d08a3b..78b3d3d1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,6 +62,8 @@ libisl_la_SOURCES = \ isl_fold.c \ isl_gmp.c \ isl_hash.c \ + isl_hmap_map_basic_set.c \ + isl_hmap_map_basic_set.h \ isl_ilp.c \ isl_input.c \ isl_list.c \ diff --git a/isl_hmap_map_basic_set.c b/isl_hmap_map_basic_set.c new file mode 100644 index 00000000..7f9a922c --- /dev/null +++ b/isl_hmap_map_basic_set.c @@ -0,0 +1,102 @@ +#include + +struct isl_map_basic_set_pair { + isl_map *key; + isl_basic_set *val; +}; + +__isl_give isl_hmap_map_basic_set *isl_hmap_map_basic_set_alloc(isl_ctx *ctx, + int min_size) +{ + return (isl_hmap_map_basic_set *) isl_hash_table_alloc(ctx, min_size); +} + +static int free_pair(void **entry, void *user) +{ + struct isl_map_basic_set_pair *pair = *entry; + isl_map_free(pair->key); + isl_basic_set_free(pair->val); + free(pair); + *entry = NULL; + return 0; +} + +void isl_hmap_map_basic_set_free(isl_ctx *ctx, + __isl_take isl_hmap_map_basic_set *hmap) +{ + if (!hmap) + return; + isl_hash_table_foreach(ctx, &hmap->table, &free_pair, NULL); + isl_hash_table_free(ctx, &hmap->table); +} + +static int has_key(const void *entry, const void *key) +{ + const struct isl_map_basic_set_pair *pair = entry; + isl_map *map = (isl_map *)key; + + return isl_map_fast_is_equal(pair->key, map); +} + +int isl_hmap_map_basic_set_has(isl_ctx *ctx, + __isl_keep isl_hmap_map_basic_set *hmap, __isl_keep isl_map *key) +{ + uint32_t hash; + + hash = isl_map_get_hash(key); + return !!isl_hash_table_find(ctx, &hmap->table, hash, &has_key, key, 0); +} + +__isl_give isl_basic_set *isl_hmap_map_basic_set_get(isl_ctx *ctx, + __isl_keep isl_hmap_map_basic_set *hmap, __isl_take isl_map *key) +{ + struct isl_hash_table_entry *entry; + struct isl_map_basic_set_pair *pair; + uint32_t hash; + + hash = isl_map_get_hash(key); + entry = isl_hash_table_find(ctx, &hmap->table, hash, &has_key, key, 0); + isl_map_free(key); + + if (!entry) + return NULL; + + pair = entry->data; + + return isl_basic_set_copy(pair->val); +} + +int isl_hmap_map_basic_set_set(isl_ctx *ctx, + __isl_keep isl_hmap_map_basic_set *hmap, __isl_take isl_map *key, + __isl_take isl_basic_set *val) +{ + struct isl_hash_table_entry *entry; + struct isl_map_basic_set_pair *pair; + uint32_t hash; + + hash = isl_map_get_hash(key); + entry = isl_hash_table_find(ctx, &hmap->table, hash, &has_key, key, 1); + + if (!entry) + return -1; + + if (entry->data) { + pair = entry->data; + isl_basic_set_free(pair->val); + pair->val = val; + isl_map_free(key); + return 0; + } + + pair = isl_alloc_type(ctx, struct isl_map_basic_set_pair); + if (!pair) { + isl_map_free(key); + isl_basic_set_free(val); + return -1; + } + + entry->data = pair; + pair->key = key; + pair->val = val; + return 0; +} diff --git a/isl_hmap_map_basic_set.h b/isl_hmap_map_basic_set.h new file mode 100644 index 00000000..905791d6 --- /dev/null +++ b/isl_hmap_map_basic_set.h @@ -0,0 +1,26 @@ +#ifndef ISL_HMAP_MAP_BASIC_SET_H +#define ISL_HMAP_MAP_BASIC_SET_H + +#include +#include +#include + +struct isl_hmap_map_basic_set { + struct isl_hash_table table; +}; +typedef struct isl_hmap_map_basic_set isl_hmap_map_basic_set; + +__isl_give isl_hmap_map_basic_set *isl_hmap_map_basic_set_alloc( isl_ctx *ctx, + int min_size); +void isl_hmap_map_basic_set_free(isl_ctx *ctx, + __isl_take isl_hmap_map_basic_set *hmap); + +int isl_hmap_map_basic_set_has(isl_ctx *ctx, + __isl_keep isl_hmap_map_basic_set *hmap, __isl_keep isl_map *key); +__isl_give isl_basic_set *isl_hmap_map_basic_set_get(isl_ctx *ctx, + __isl_keep isl_hmap_map_basic_set *hmap, __isl_take isl_map *key); +int isl_hmap_map_basic_set_set(isl_ctx *ctx, + __isl_keep isl_hmap_map_basic_set *hmap, __isl_take isl_map *key, + __isl_take isl_basic_set *val); + +#endif -- 2.11.4.GIT