1 /* dict - a generic dictionary, variation over hash table */
3 /* Copyright (c) 2004-2019. The SimGrid Team. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "dict_private.h" /* prototypes of this module */
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict_elm, xbt_dict, "Dictionaries internals");
12 xbt_mallocator_t dict_elm_mallocator = NULL;
14 xbt_dictelm_t xbt_dictelm_new(const char* key, int key_len, unsigned int hash_code, void* content)
16 xbt_dictelm_t element = xbt_mallocator_get(dict_elm_mallocator);
17 element->key = xbt_new(char, key_len + 1);
18 memcpy(element->key, key, key_len);
19 element->key[key_len] = '\0';
21 element->key_len = key_len;
22 element->hash_code = hash_code;
24 element->content = content;
30 void xbt_dictelm_free(xbt_dict_t dict, xbt_dictelm_t element)
33 char *key = element->key;
34 void *content = element->content;
35 void_f_pvoid_t free_f;
36 free_f = dict->free_f;
37 xbt_mallocator_release(dict_elm_mallocator, element);
40 if (free_f && content)
45 void xbt_dictelm_set_data(xbt_dict_t dict, xbt_dictelm_t element, void* data)
47 void_f_pvoid_t free_f = dict->free_f;
48 if (free_f && element->content)
49 free_f(element->content);
51 element->content = data;
54 void *dict_elm_mallocator_new_f(void)
56 return xbt_new(s_xbt_dictelm_t, 1);