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 return (isl_map_to_basic_set
*) isl_hash_table_alloc(ctx
, min_size
);
24 static int free_pair(void **entry
, void *user
)
26 struct isl_map_basic_set_pair
*pair
= *entry
;
27 isl_map_free(pair
->key
);
28 isl_basic_set_free(pair
->val
);
34 void *isl_map_to_basic_set_free(isl_ctx
*ctx
,
35 __isl_take isl_map_to_basic_set
*hmap
)
39 isl_hash_table_foreach(ctx
, &hmap
->table
, &free_pair
, NULL
);
40 isl_hash_table_free(ctx
, &hmap
->table
);
44 static int has_key(const void *entry
, const void *key
)
46 const struct isl_map_basic_set_pair
*pair
= entry
;
47 isl_map
*map
= (isl_map
*)key
;
49 return isl_map_plain_is_equal(pair
->key
, map
);
52 int isl_map_to_basic_set_has(isl_ctx
*ctx
,
53 __isl_keep isl_map_to_basic_set
*hmap
, __isl_keep isl_map
*key
)
57 hash
= isl_map_get_hash(key
);
58 return !!isl_hash_table_find(ctx
, &hmap
->table
, hash
, &has_key
, key
, 0);
61 __isl_give isl_basic_set
*isl_map_to_basic_set_get(isl_ctx
*ctx
,
62 __isl_keep isl_map_to_basic_set
*hmap
, __isl_take isl_map
*key
)
64 struct isl_hash_table_entry
*entry
;
65 struct isl_map_basic_set_pair
*pair
;
68 hash
= isl_map_get_hash(key
);
69 entry
= isl_hash_table_find(ctx
, &hmap
->table
, hash
, &has_key
, key
, 0);
77 return isl_basic_set_copy(pair
->val
);
80 int isl_map_to_basic_set_set(isl_ctx
*ctx
,
81 __isl_keep isl_map_to_basic_set
*hmap
, __isl_take isl_map
*key
,
82 __isl_take isl_basic_set
*val
)
84 struct isl_hash_table_entry
*entry
;
85 struct isl_map_basic_set_pair
*pair
;
88 hash
= isl_map_get_hash(key
);
89 entry
= isl_hash_table_find(ctx
, &hmap
->table
, hash
, &has_key
, key
, 1);
96 isl_basic_set_free(pair
->val
);
102 pair
= isl_alloc_type(ctx
, struct isl_map_basic_set_pair
);
112 isl_basic_set_free(val
);