1 /* dict - a generic dictionary, variation over hash table */
3 /* Copyright (c) 2004-2018. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
16 #include "xbt/mallocator.h"
17 #include "src/xbt_modinter.h"
19 #include "dict_private.h"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict, xbt, "Dictionaries provide the same functionalities as hash tables");
25 * \param free_ctn function to call with (\a data as argument) when \a data is removed from the dictionary
26 * \return pointer to the destination
27 * \see xbt_dict_free()
29 * Creates and initialize a new dictionary with a default hashtable size.
30 * The dictionary is homogeneous: each element share the same free function.
32 xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn)
34 if (dict_elm_mallocator == nullptr)
39 dict = xbt_new(s_xbt_dict_t, 1);
40 dict->free_f = free_ctn;
41 dict->table_size = 127;
42 dict->table = xbt_new0(xbt_dictelm_t, dict->table_size + 1);
51 * \param dict the dictionary to be freed
53 * Frees a dictionary with all the data
55 void xbt_dict_free(xbt_dict_t * dict)
57 if (dict != nullptr && *dict != nullptr) {
58 int table_size = (*dict)->table_size;
59 xbt_dictelm_t* table = (*dict)->table;
60 /* Warning: the size of the table is 'table_size+1'...
61 * This is because table_size is used as a binary mask in xbt_dict_rehash */
62 for (int i = 0; (*dict)->count && i <= table_size; i++) {
63 xbt_dictelm_t current = table[i];
64 xbt_dictelm_t previous;
66 while (current != nullptr) {
68 current = current->next;
69 xbt_dictelm_free(*dict, previous);
79 /** Returns the amount of elements in the dict */
80 unsigned int xbt_dict_size(xbt_dict_t dict)
82 return (dict != nullptr ? static_cast<unsigned int>(dict->count) : static_cast<unsigned int>(0));
85 /* Expend the size of the dict */
86 static void xbt_dict_rehash(xbt_dict_t dict)
88 const unsigned oldsize = dict->table_size + 1;
89 unsigned newsize = oldsize * 2;
91 xbt_dictelm_t *currcell = (xbt_dictelm_t *) xbt_realloc((char *) dict->table, newsize * sizeof(xbt_dictelm_t));
92 memset(&currcell[oldsize], 0, oldsize * sizeof(xbt_dictelm_t)); /* zero second half */
94 dict->table_size = newsize;
95 dict->table = currcell;
96 XBT_DEBUG("REHASH (%u->%u)", oldsize, newsize);
98 for (unsigned i = 0; i < oldsize; i++, currcell++) {
99 if (*currcell == nullptr) /* empty cell */
102 xbt_dictelm_t *twincell = currcell + oldsize;
103 xbt_dictelm_t *pprev = currcell;
104 xbt_dictelm_t bucklet = *currcell;
105 for (; bucklet != nullptr; bucklet = *pprev) {
106 /* Since we use "& size" instead of "%size" and since the size was doubled, each bucklet of this cell must either:
107 - stay in cell i (ie, currcell)
108 - go to the cell i+oldsize (ie, twincell) */
109 if ((bucklet->hash_code & newsize) != i) { /* Move to b */
110 *pprev = bucklet->next;
111 bucklet->next = *twincell;
112 if (*twincell == nullptr)
116 pprev = &bucklet->next;
120 if (*currcell == nullptr) /* everything moved */
126 * \brief Add data to the dict (arbitrary key)
127 * \param dict the container
128 * \param key the key to set the new data
129 * \param key_len the size of the \a key
130 * \param data the data to add in the dict
131 * \param free_ctn unused parameter (kept for compatibility)
133 * Set the \a data in the structure under the \a key, which can be any kind of data, as long as its length is provided
136 void xbt_dict_set_ext(xbt_dict_t dict, const char* key, int key_len, void* data,
137 XBT_ATTRIB_UNUSED void_f_pvoid_t free_ctn)
139 unsigned int hash_code = xbt_str_hash_ext(key, key_len);
141 xbt_dictelm_t current;
142 xbt_dictelm_t previous = nullptr;
144 XBT_CDEBUG(xbt_dict, "ADD %.*s hash = %u, size = %d, & = %u", key_len, key, hash_code,
145 dict->table_size, hash_code & dict->table_size);
146 current = dict->table[hash_code & dict->table_size];
147 while (current != nullptr && (hash_code != current->hash_code || key_len != current->key_len
148 || memcmp(key, current->key, key_len))) {
150 current = current->next;
153 if (current == nullptr) {
154 /* this key doesn't exist yet */
155 current = xbt_dictelm_new(key, key_len, hash_code, data);
157 if (previous == nullptr) {
158 dict->table[hash_code & dict->table_size] = current;
160 if ((dict->fill * 100) / (dict->table_size + 1) > MAX_FILL_PERCENT)
161 xbt_dict_rehash(dict);
163 previous->next = current;
166 XBT_CDEBUG(xbt_dict, "Replace %.*s by %.*s under key %.*s",
167 key_len, (char *) current->content, key_len, (char *) data, key_len, (char *) key);
168 /* there is already an element with the same key: overwrite it */
169 xbt_dictelm_set_data(dict, current, data);
174 * \brief Add data to the dict (null-terminated key)
176 * \param dict the dict
177 * \param key the key to set the new data
178 * \param data the data to add in the dict
179 * \param free_ctn unused parameter (kept for compatibility)
181 * set the \a data in the structure under the \a key, which is anull terminated string.
183 void xbt_dict_set(xbt_dict_t dict, const char *key, void *data, void_f_pvoid_t free_ctn)
185 xbt_dict_set_ext(dict, key, strlen(key), data, free_ctn);
189 * \brief Retrieve data from the dict (arbitrary key)
191 * \param dict the dealer of data
192 * \param key the key to find data
193 * \param key_len the size of the \a key
194 * \return the data that we are looking for
196 * Search the given \a key. Throws not_found_error when not found.
198 void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
200 unsigned int hash_code = xbt_str_hash_ext(key, key_len);
201 xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
203 while (current != nullptr && (hash_code != current->hash_code || key_len != current->key_len
204 || memcmp(key, current->key, key_len))) {
205 current = current->next;
208 if (current == nullptr)
209 THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
211 return current->content;
214 /** @brief like xbt_dict_get_ext(), but returning nullptr when not found */
215 void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len)
217 unsigned int hash_code = xbt_str_hash_ext(key, key_len);
218 xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
220 while (current != nullptr && (hash_code != current->hash_code || key_len != current->key_len
221 || memcmp(key, current->key, key_len))) {
222 current = current->next;
225 if (current == nullptr)
228 return current->content;
232 * @brief retrieve the key associated to that object. Warning, that's a linear search
234 * Returns nullptr if the object cannot be found
236 char *xbt_dict_get_key(xbt_dict_t dict, const void *data)
238 for (int i = 0; i <= dict->table_size; i++) {
239 xbt_dictelm_t current = dict->table[i];
240 while (current != nullptr) {
241 if (current->content == data)
243 current = current->next;
250 * \brief Retrieve data from the dict (null-terminated key)
252 * \param dict the dealer of data
253 * \param key the key to find data
254 * \return the data that we are looking for
256 * Search the given \a key. Throws not_found_error when not found.
257 * Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
259 void *xbt_dict_get(xbt_dict_t dict, const char *key)
261 return xbt_dict_get_elm(dict, key)->content;
265 * \brief Retrieve element from the dict (null-terminated key)
267 * \param dict the dealer of data
268 * \param key the key to find data
269 * \return the s_xbt_dictelm_t that we are looking for
271 * Search the given \a key. Throws not_found_error when not found.
272 * Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
274 xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
276 xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
278 if (current == nullptr)
279 THROWF(not_found_error, 0, "key %s not found", key);
285 * \brief like xbt_dict_get(), but returning nullptr when not found
287 void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key)
289 xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
291 if (current == nullptr)
294 return current->content;
298 * \brief like xbt_dict_get_elm(), but returning nullptr when not found
300 xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key)
302 unsigned int hash_code = xbt_str_hash(key);
303 xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
305 while (current != nullptr && (hash_code != current->hash_code || strcmp(key, current->key)))
306 current = current->next;
311 * \brief Remove data from the dict (arbitrary key)
313 * \param dict the trash can
314 * \param key the key of the data to be removed
315 * \param key_len the size of the \a key
317 * Remove the entry associated with the given \a key (throws not_found)
319 void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len)
321 unsigned int hash_code = xbt_str_hash_ext(key, key_len);
322 xbt_dictelm_t previous = nullptr;
323 xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
325 while (current != nullptr && (hash_code != current->hash_code || key_len != current->key_len
326 || strncmp(key, current->key, key_len))) {
327 previous = current; /* save the previous node */
328 current = current->next;
331 if (current == nullptr)
332 THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
334 if (previous != nullptr) {
335 previous->next = current->next;
337 dict->table[hash_code & dict->table_size] = current->next;
341 if (not dict->table[hash_code & dict->table_size])
344 xbt_dictelm_free(dict, current);
349 * \brief Remove data from the dict (null-terminated key)
351 * \param dict the dict
352 * \param key the key of the data to be removed
354 * Remove the entry associated with the given \a key
356 void xbt_dict_remove(xbt_dict_t dict, const char *key)
358 xbt_dict_remove_ext(dict, key, strlen(key));
361 /** @brief Remove all data from the dict */
362 void xbt_dict_reset(xbt_dict_t dict)
364 if (dict->count == 0)
367 for (int i = 0; i <= dict->table_size; i++) {
368 xbt_dictelm_t previous = nullptr;
369 xbt_dictelm_t current = dict->table[i];
370 while (current != nullptr) {
372 current = current->next;
373 xbt_dictelm_free(dict, previous);
375 dict->table[i] = nullptr;
383 * \brief Return the number of elements in the dict.
384 * \param dict a dictionary
386 int xbt_dict_length(xbt_dict_t dict)
392 * \brief test if the dict is empty or not
394 int xbt_dict_is_empty(xbt_dict_t dict)
396 return not dict || (xbt_dict_length(dict) == 0);
400 * \brief Outputs the content of the structure (debugging purpose)
402 * \param dict the exibitionist
403 * \param output a function to dump each data in the tree
405 * Outputs the content of the structure. (for debugging purpose).
406 * \a output is a function to output the data. If nullptr, data won't be displayed.
408 void xbt_dict_dump(xbt_dict_t dict, void_f_pvoid_t output)
410 xbt_dictelm_t element;
411 printf("Dict %p:\n", dict);
412 if (dict != nullptr) {
413 for (int i = 0; i < dict->table_size; i++) {
414 element = dict->table[i];
417 while (element != nullptr) {
418 printf(" %s -> '", element->key);
419 if (output != nullptr) {
420 output(element->content);
423 element = element->next;
434 * Create the dict mallocators.
435 * This is an internal XBT function called during the lib initialization.
436 * It can be used several times to recreate the mallocator, for example when you switch to MC mode
438 void xbt_dict_preinit()
440 if (dict_elm_mallocator == nullptr)
441 dict_elm_mallocator = xbt_mallocator_new(256, dict_elm_mallocator_new_f, dict_elm_mallocator_free_f,
442 dict_elm_mallocator_reset_f);
446 * Destroy the dict mallocators.
447 * This is an internal XBT function during the lib initialization
449 void xbt_dict_postexit()
451 if (dict_elm_mallocator != nullptr) {
452 xbt_mallocator_free(dict_elm_mallocator);
453 dict_elm_mallocator = nullptr;
458 #include "src/internal_config.h"
462 #include <xbt/ex.hpp>
464 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(xbt_dict);
466 XBT_TEST_SUITE("dict", "Dict data container");
468 static void debugged_add_ext(xbt_dict_t head, const char* key, const char* data_to_fill)
470 char *data = xbt_strdup(data_to_fill);
472 xbt_test_log("Add %s under %s", data_to_fill, key);
474 xbt_dict_set(head, key, data, nullptr);
475 if (XBT_LOG_ISENABLED(xbt_dict, xbt_log_priority_debug)) {
476 xbt_dict_dump(head, [](void* s) { fputs((char*)s, stdout); });
481 static void debugged_add(xbt_dict_t head, const char* key)
483 debugged_add_ext(head, key, key);
486 static xbt_dict_t new_fixture()
488 xbt_test_add("Fill in the dictionnary");
490 xbt_dict_t head = xbt_dict_new_homogeneous(&free);
491 debugged_add(head, "12");
492 debugged_add(head, "12a");
493 debugged_add(head, "12b");
494 debugged_add(head, "123");
495 debugged_add(head, "123456");
496 debugged_add(head, "1234");
497 debugged_add(head, "123457");
502 static void search_ext(xbt_dict_t head, const char *key, const char *data)
504 xbt_test_add("Search %s", key);
505 char *found = (char*) xbt_dict_get(head, key);
506 xbt_test_log("Found %s", found);
508 xbt_test_assert(found, "data do not match expectations: found nullptr while searching for %s", data);
510 xbt_test_assert(not strcmp(data, found), "data do not match expectations: found %s while searching for %s", found,
513 xbt_test_assert(not found, "data do not match expectations: found %s while searching for nullptr", found);
517 static void search(xbt_dict_t head, const char *key)
519 search_ext(head, key, key);
522 static void debugged_remove(xbt_dict_t head, const char* key)
524 xbt_test_add("Remove '%s'", key);
525 xbt_dict_remove(head, key);
528 static void traverse(xbt_dict_t head)
530 xbt_dict_cursor_t cursor = nullptr;
535 xbt_dict_foreach(head, cursor, key, data) {
536 if (not key || not data || strcmp(key, data)) {
537 xbt_test_log("Seen #%d: %s->%s", ++i, key, data);
539 xbt_test_log("Seen #%d: %s", ++i, key);
541 xbt_test_assert(key && data && strcmp(key, data) == 0, "Key(%s) != value(%s). Aborting", key, data);
545 static void search_not_found(xbt_dict_t head, const char *data)
548 xbt_test_add("Search %s (expected not to be found)", data);
551 data = (const char*) xbt_dict_get(head, data);
552 THROWF(unknown_error, 0, "Found something which shouldn't be there (%s)", data);
555 if (e.category != not_found_error)
556 xbt_test_exception(e);
559 xbt_test_assert(ok, "Exception not raised");
562 static void count(xbt_dict_t dict, int length)
564 xbt_test_add("Count elements (expecting %d)", length);
565 xbt_test_assert(xbt_dict_length(dict) == length, "Announced length(%d) != %d.", xbt_dict_length(dict), length);
567 xbt_dict_cursor_t cursor;
571 xbt_dict_foreach(dict, cursor, key, data)
574 xbt_test_assert(effective == length, "Effective length(%d) != %d.", effective, length);
577 static void count_check_get_key(xbt_dict_t dict, int length)
579 xbt_dict_cursor_t cursor;
584 xbt_test_add("Count elements (expecting %d), and test the getkey function", length);
585 xbt_test_assert(xbt_dict_length(dict) == length, "Announced length(%d) != %d.", xbt_dict_length(dict), length);
587 xbt_dict_foreach(dict, cursor, key, data) {
589 char* key2 = xbt_dict_get_key(dict, data);
590 xbt_assert(not strcmp(key, key2), "The data was registered under %s instead of %s as expected", key2, key);
593 xbt_test_assert(effective == length, "Effective length(%d) != %d.", effective, length);
596 XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve and traverse homogeneous dicts")
598 xbt_test_add("Traversal the null dictionary");
601 xbt_test_add("Traversal and search the empty dictionary");
602 xbt_dict_t head = xbt_dict_new_homogeneous(&free);
605 debugged_remove(head, "12346");
608 if (e.category != not_found_error)
609 xbt_test_exception(e);
611 xbt_dict_free(&head);
613 xbt_test_add("Traverse the full dictionary");
614 head = new_fixture();
615 count_check_get_key(head, 7);
617 debugged_add_ext(head, "toto", "tutu");
618 search_ext(head, "toto", "tutu");
619 debugged_remove(head, "toto");
624 xbt_test_add("Free the dictionary (twice)");
625 xbt_dict_free(&head);
626 xbt_dict_free(&head);
629 head = new_fixture();
630 count_check_get_key(head, 7);
631 xbt_test_add("Change 123 to 'Changed 123'");
632 xbt_dict_set(head, "123", xbt_strdup("Changed 123"), nullptr);
633 count_check_get_key(head, 7);
635 xbt_test_add("Change 123 back to '123'");
636 xbt_dict_set(head, "123", xbt_strdup("123"), nullptr);
637 count_check_get_key(head, 7);
639 xbt_test_add("Change 12a to 'Dummy 12a'");
640 xbt_dict_set(head, "12a", xbt_strdup("Dummy 12a"), nullptr);
641 count_check_get_key(head, 7);
643 xbt_test_add("Change 12a to '12a'");
644 xbt_dict_set(head, "12a", xbt_strdup("12a"), nullptr);
645 count_check_get_key(head, 7);
647 xbt_test_add("Traverse the resulting dictionary");
651 xbt_test_add("Search 123");
652 char* data = (char*)xbt_dict_get(head, "123");
653 xbt_test_assert(data && strcmp("123", data) == 0);
655 search_not_found(head, "Can't be found");
656 search_not_found(head, "123 Can't be found");
657 search_not_found(head, "12345678 NOT");
662 search(head, "123456");
663 search(head, "1234");
664 search(head, "123457");
666 xbt_test_add("Traverse the resulting dictionary");
669 xbt_test_add("Free the dictionary twice");
670 xbt_dict_free(&head);
671 xbt_dict_free(&head);
673 xbt_test_add("Traverse the resulting dictionary");
677 XBT_TEST_UNIT("remove_homogeneous", test_dict_remove, "Removing some values from homogeneous dicts")
679 xbt_dict_t head = new_fixture();
681 xbt_test_add("Remove non existing data");
683 debugged_remove(head, "Does not exist");
686 if (e.category != not_found_error)
687 xbt_test_exception(e);
691 xbt_dict_free(&head);
693 xbt_test_add("Remove each data manually (traversing the resulting dictionary each time)");
694 head = new_fixture();
695 debugged_remove(head, "12a");
698 debugged_remove(head, "12b");
701 debugged_remove(head, "12");
704 debugged_remove(head, "123456");
708 debugged_remove(head, "12346");
711 if (e.category != not_found_error)
712 xbt_test_exception(e);
715 debugged_remove(head, "1234");
717 debugged_remove(head, "123457");
719 debugged_remove(head, "123");
722 debugged_remove(head, "12346");
725 if (e.category != not_found_error)
726 xbt_test_exception(e);
730 xbt_test_add("Free dict, create new fresh one, and then reset the dict");
731 xbt_dict_free(&head);
732 head = new_fixture();
733 xbt_dict_reset(head);
737 xbt_test_add("Free the dictionary twice");
738 xbt_dict_free(&head);
739 xbt_dict_free(&head);
742 XBT_TEST_UNIT("nulldata", test_dict_nulldata, "nullptr data management")
744 xbt_dict_t head = new_fixture();
746 xbt_test_add("Store nullptr under 'null'");
747 xbt_dict_set(head, "null", nullptr, nullptr);
748 search_ext(head, "null", nullptr);
750 xbt_test_add("Check whether I see it while traversing...");
752 xbt_dict_cursor_t cursor = nullptr;
757 xbt_dict_foreach(head, cursor, key, data) {
758 if (not key || not data || strcmp(key, data)) {
759 xbt_test_log("Seen: %s->%s", key, data);
761 xbt_test_log("Seen: %s", key);
764 if (key && strcmp(key, "null") == 0)
767 xbt_test_assert(found, "the key 'null', associated to nullptr is not found");
769 xbt_dict_free(&head);
773 #define SIZEOFKEY 1024
774 static int countelems(xbt_dict_t head)
776 xbt_dict_cursor_t cursor;
781 xbt_dict_foreach(head, cursor, key, data) {
787 XBT_TEST_UNIT("crash", test_dict_crash, "Crash test")
789 srand((unsigned int) time(nullptr));
791 for (int i = 0; i < 10; i++) {
792 xbt_test_add("CRASH test number %d (%d to go)", i + 1, 10 - i - 1);
793 xbt_test_log("Fill the struct, count its elems and frees the structure");
794 xbt_test_log("using 1000 elements with %d chars long randomized keys.", SIZEOFKEY);
795 xbt_dict_t head = xbt_dict_new_homogeneous(free);
796 for (int j = 0; j < 1000; j++) {
797 char* data = nullptr;
798 char* key = (char*)xbt_malloc(SIZEOFKEY);
801 for (int k = 0; k < SIZEOFKEY - 1; k++)
802 key[k] = rand() % ('z' - 'a') + 'a';
803 key[SIZEOFKEY - 1] = '\0';
804 data = (char*) xbt_dict_get_or_null(head, key);
805 } while (data != nullptr);
807 xbt_dict_set(head, key, key, nullptr);
808 data = (char*) xbt_dict_get(head, key);
809 xbt_test_assert(not strcmp(key, data), "Retrieved value (%s) != Injected value (%s)", key, data);
814 xbt_dict_free(&head);
815 xbt_dict_free(&head);
818 xbt_dict_t head = xbt_dict_new_homogeneous(&free);
819 xbt_test_add("Fill %d elements, with keys being the number of element", NB_ELM);
820 for (int j = 0; j < NB_ELM; j++) {
821 char* key = (char*)xbt_malloc(10);
823 snprintf(key,10, "%d", j);
824 xbt_dict_set(head, key, key, nullptr);
827 xbt_test_add("Count the elements (retrieving the key and data for each)");
828 xbt_test_log("There is %d elements", countelems(head));
830 xbt_test_add("Search my %d elements 20 times", NB_ELM);
831 char* key = (char*)xbt_malloc(10);
832 for (int i = 0; i < 20; i++) {
833 for (int j = 0; j < NB_ELM; j++) {
834 snprintf(key,10, "%d", j);
835 void* data = xbt_dict_get(head, key);
836 xbt_test_assert(not strcmp(key, (char*)data), "with get, key=%s != data=%s", key, (char*)data);
837 data = xbt_dict_get_ext(head, key, strlen(key));
838 xbt_test_assert(not strcmp(key, (char*)data), "with get_ext, key=%s != data=%s", key, (char*)data);
843 xbt_test_add("Remove my %d elements", NB_ELM);
844 key = (char*) xbt_malloc(10);
845 for (int j = 0; j < NB_ELM; j++) {
846 snprintf(key,10, "%d", j);
847 xbt_dict_remove(head, key);
851 xbt_test_add("Free the object (twice)");
852 xbt_dict_free(&head);
853 xbt_dict_free(&head);
856 XBT_TEST_UNIT("ext", test_dict_int, "Test dictionnary with int keys")
858 xbt_dict_t dict = xbt_dict_new_homogeneous(nullptr);
861 xbt_test_add("Insert elements");
862 for (int i = 0; i < count; ++i)
863 xbt_dict_set_ext(dict, (char*) &i, sizeof(i), (void*) (intptr_t) i, nullptr);
864 xbt_test_assert(xbt_dict_size(dict) == (unsigned) count, "Bad number of elements in the dictionnary");
866 xbt_test_add("Check elements");
867 for (int i = 0; i < count; ++i) {
868 int res = (int) (intptr_t) xbt_dict_get_ext(dict, (char*) &i, sizeof(i));
869 xbt_test_assert(xbt_dict_size(dict) == (unsigned) count, "Unexpected value at index %i, expected %i but was %i", i, i, res);
872 xbt_test_add("Free the array");
873 xbt_dict_free(&dict);
875 #endif /* SIMGRID_TEST */