if (dict_elm_mallocator != NULL) {
/* Already created. I guess we want to switch to MC mode, so kill the previously created mallocator */
xbt_mallocator_free(dict_elm_mallocator);
+ xbt_mallocator_free(dict_het_elm_mallocator);
}
dict_elm_mallocator = xbt_mallocator_new(256,
dict_elm_mallocator_new_f,
dict_elm_mallocator_free_f,
dict_elm_mallocator_reset_f);
+ dict_het_elm_mallocator = xbt_mallocator_new(256,
+ dict_het_elm_mallocator_new_f,
+ dict_het_elm_mallocator_free_f,
+ dict_het_elm_mallocator_reset_f);
}
/**
if (dict_elm_mallocator != NULL) {
xbt_mallocator_free(dict_elm_mallocator);
dict_elm_mallocator = NULL;
+ xbt_mallocator_free(dict_het_elm_mallocator);
+ dict_het_elm_mallocator = NULL;
}
if (all_sizes) {
unsigned int count;
"Dictionaries internals: post-removal cleanup");
xbt_mallocator_t dict_elm_mallocator = NULL;
+xbt_mallocator_t dict_het_elm_mallocator = NULL;
xbt_dictelm_t xbt_dictelm_new(xbt_dict_t dict, const char *key, int key_len,
unsigned int hash_code, void *content,
void_f_pvoid_t free_f)
{
- xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator);
+ xbt_het_dictelm_t het_element = xbt_mallocator_get(dict_het_elm_mallocator);
+ xbt_dictelm_t element = &het_element->element;
element->key = xbt_new(char, key_len + 1);
memcpy((void *) element->key, (void *) key, key_len);
element->hash_code = hash_code;
element->content = content;
- element->free_f = free_f;
+ het_element->free_f = free_f;
element->next = NULL;
return element;
void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element)
{
if (element != NULL) {
+ xbt_het_dictelm_t het_element = (xbt_het_dictelm_t)element;
xbt_free(element->key);
- if (element->free_f != NULL && element->content != NULL) {
- element->free_f(element->content);
+ if (het_element->free_f != NULL && element->content != NULL) {
+ het_element->free_f(element->content);
}
- xbt_mallocator_release(dict_elm_mallocator, element);
+ xbt_mallocator_release(dict_het_elm_mallocator, het_element);
}
}
void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element,
void *data, void_f_pvoid_t free_ctn)
{
- if (element->free_f && element->content)
- element->free_f(element->content);
+ xbt_het_dictelm_t het_element = (xbt_het_dictelm_t)element;
+ if (het_element->free_f && element->content)
+ het_element->free_f(element->content);
element->content = data;
- element->free_f = free_ctn;
+ het_element->free_f = free_ctn;
}
void *dict_elm_mallocator_new_f(void)
{
return xbt_new(s_xbt_dictelm_t, 1);
}
+
+void *dict_het_elm_mallocator_new_f(void)
+{
+ return xbt_new(s_xbt_het_dictelm_t, 1);
+}
unsigned int hash_code;
void *content;
- void_f_pvoid_t free_f;
xbt_dictelm_t next;
} s_xbt_dictelm_t;
+typedef struct s_xbt_het_dictelm {
+ s_xbt_dictelm_t element;
+ void_f_pvoid_t free_f;
+} s_xbt_het_dictelm_t, *xbt_het_dictelm_t;
+
typedef struct s_xbt_dict {
void_f_pvoid_t free_f;
xbt_dictelm_t *table;
#define dict_elm_mallocator_free_f xbt_free_f
#define dict_elm_mallocator_reset_f ((void_f_pvoid_t)NULL)
+extern xbt_mallocator_t dict_het_elm_mallocator;
+extern void *dict_het_elm_mallocator_new_f(void);
+#define dict_het_elm_mallocator_free_f xbt_free_f
+#define dict_het_elm_mallocator_reset_f ((void_f_pvoid_t)NULL)
+
/*####[ Function prototypes ]################################################*/
xbt_dictelm_t xbt_dictelm_new(xbt_dict_t dict, const char *key, int key_len,
unsigned int hash_code, void *content,