Transform isl_point_print into isl_printer_print_point
[isl.git] / isl_hmap_map_basic_set.c
blobb303516f03109053d4e6ea529c6e03348829b750
1 #include <isl_hmap_map_basic_set.h>
3 struct isl_map_basic_set_pair {
4 isl_map *key;
5 isl_basic_set *val;
6 };
8 __isl_give isl_hmap_map_basic_set *isl_hmap_map_basic_set_alloc(isl_ctx *ctx,
9 int min_size)
11 return (isl_hmap_map_basic_set *) isl_hash_table_alloc(ctx, min_size);
14 static int free_pair(void **entry, void *user)
16 struct isl_map_basic_set_pair *pair = *entry;
17 isl_map_free(pair->key);
18 isl_basic_set_free(pair->val);
19 free(pair);
20 *entry = NULL;
21 return 0;
24 void isl_hmap_map_basic_set_free(isl_ctx *ctx,
25 __isl_take isl_hmap_map_basic_set *hmap)
27 if (!hmap)
28 return;
29 isl_hash_table_foreach(ctx, &hmap->table, &free_pair, NULL);
30 isl_hash_table_free(ctx, &hmap->table);
33 static int has_key(const void *entry, const void *key)
35 const struct isl_map_basic_set_pair *pair = entry;
36 isl_map *map = (isl_map *)key;
38 return isl_map_plain_is_equal(pair->key, map);
41 int isl_hmap_map_basic_set_has(isl_ctx *ctx,
42 __isl_keep isl_hmap_map_basic_set *hmap, __isl_keep isl_map *key)
44 uint32_t hash;
46 hash = isl_map_get_hash(key);
47 return !!isl_hash_table_find(ctx, &hmap->table, hash, &has_key, key, 0);
50 __isl_give isl_basic_set *isl_hmap_map_basic_set_get(isl_ctx *ctx,
51 __isl_keep isl_hmap_map_basic_set *hmap, __isl_take isl_map *key)
53 struct isl_hash_table_entry *entry;
54 struct isl_map_basic_set_pair *pair;
55 uint32_t hash;
57 hash = isl_map_get_hash(key);
58 entry = isl_hash_table_find(ctx, &hmap->table, hash, &has_key, key, 0);
59 isl_map_free(key);
61 if (!entry)
62 return NULL;
64 pair = entry->data;
66 return isl_basic_set_copy(pair->val);
69 int isl_hmap_map_basic_set_set(isl_ctx *ctx,
70 __isl_keep isl_hmap_map_basic_set *hmap, __isl_take isl_map *key,
71 __isl_take isl_basic_set *val)
73 struct isl_hash_table_entry *entry;
74 struct isl_map_basic_set_pair *pair;
75 uint32_t hash;
77 hash = isl_map_get_hash(key);
78 entry = isl_hash_table_find(ctx, &hmap->table, hash, &has_key, key, 1);
80 if (!entry)
81 return -1;
83 if (entry->data) {
84 pair = entry->data;
85 isl_basic_set_free(pair->val);
86 pair->val = val;
87 isl_map_free(key);
88 return 0;
91 pair = isl_alloc_type(ctx, struct isl_map_basic_set_pair);
92 if (!pair) {
93 isl_map_free(key);
94 isl_basic_set_free(val);
95 return -1;
98 entry->data = pair;
99 pair->key = key;
100 pair->val = val;
101 return 0;