2 * Copyright 2011 INRIA Saclay
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
11 #include <isl_map_to_basic_set.h>
13 struct isl_map_basic_set_pair
{
18 __isl_give isl_map_to_basic_set
*isl_map_to_basic_set_alloc(isl_ctx
*ctx
,
21 isl_map_to_basic_set
*hmap
;
23 hmap
= isl_calloc_type(ctx
, isl_map_to_basic_set
);
30 if (isl_hash_table_init(ctx
, &hmap
->table
, min_size
) < 0)
31 return isl_map_to_basic_set_free(hmap
);
36 static int free_pair(void **entry
, void *user
)
38 struct isl_map_basic_set_pair
*pair
= *entry
;
39 isl_map_free(pair
->key
);
40 isl_basic_set_free(pair
->val
);
46 void *isl_map_to_basic_set_free(__isl_take isl_map_to_basic_set
*hmap
)
50 isl_hash_table_foreach(hmap
->ctx
, &hmap
->table
, &free_pair
, NULL
);
51 isl_hash_table_clear(&hmap
->table
);
52 isl_ctx_deref(hmap
->ctx
);
57 isl_ctx
*isl_map_to_basic_set_get_ctx(__isl_keep isl_map_to_basic_set
*hmap
)
59 return hmap
? hmap
->ctx
: NULL
;
62 static int has_key(const void *entry
, const void *key
)
64 const struct isl_map_basic_set_pair
*pair
= entry
;
65 isl_map
*map
= (isl_map
*)key
;
67 return isl_map_plain_is_equal(pair
->key
, map
);
70 int isl_map_to_basic_set_has(__isl_keep isl_map_to_basic_set
*hmap
,
71 __isl_keep isl_map
*key
)
78 hash
= isl_map_get_hash(key
);
79 return !!isl_hash_table_find(hmap
->ctx
, &hmap
->table
, hash
,
83 __isl_give isl_basic_set
*isl_map_to_basic_set_get(
84 __isl_keep isl_map_to_basic_set
*hmap
, __isl_take isl_map
*key
)
86 struct isl_hash_table_entry
*entry
;
87 struct isl_map_basic_set_pair
*pair
;
93 hash
= isl_map_get_hash(key
);
94 entry
= isl_hash_table_find(hmap
->ctx
, &hmap
->table
, hash
,
103 return isl_basic_set_copy(pair
->val
);
109 int isl_map_to_basic_set_set(__isl_keep isl_map_to_basic_set
*hmap
,
110 __isl_take isl_map
*key
, __isl_take isl_basic_set
*val
)
112 struct isl_hash_table_entry
*entry
;
113 struct isl_map_basic_set_pair
*pair
;
119 hash
= isl_map_get_hash(key
);
120 entry
= isl_hash_table_find(hmap
->ctx
, &hmap
->table
, hash
,
128 isl_basic_set_free(pair
->val
);
134 pair
= isl_alloc_type(hmap
->ctx
, struct isl_map_basic_set_pair
);
144 isl_basic_set_free(val
);