add isl_hmap_map_basic_set
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 9 Apr 2011 18:18:18 +0000 (20:18 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 21 Apr 2011 11:13:11 +0000 (13:13 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
Makefile.am
isl_hmap_map_basic_set.c [new file with mode: 0644]
isl_hmap_map_basic_set.h [new file with mode: 0644]

index c8d08a3..78b3d3d 100644 (file)
@@ -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 (file)
index 0000000..7f9a922
--- /dev/null
@@ -0,0 +1,102 @@
+#include <isl_hmap_map_basic_set.h>
+
+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 (file)
index 0000000..905791d
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef ISL_HMAP_MAP_BASIC_SET_H
+#define ISL_HMAP_MAP_BASIC_SET_H
+
+#include <isl/hash.h>
+#include <isl/map.h>
+#include <isl/set.h>
+
+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