memset(&currcell[oldsize], 0, oldsize * sizeof(xbt_dictelm_t)); /* zero second half */
dict->table_size = --newsize;
dict->table = currcell;
memset(&currcell[oldsize], 0, oldsize * sizeof(xbt_dictelm_t)); /* zero second half */
dict->table_size = --newsize;
dict->table = currcell;
for (i = 0; i < oldsize; i++, currcell++) {
if (!*currcell) /* empty cell */
for (i = 0; i < oldsize; i++, currcell++) {
if (!*currcell) /* empty cell */
* \param key the key to set the new data
* \param key_len the size of the \a key
* \param data the data to add in the dict
* \param key the key to set the new data
* \param key_len the size of the \a key
* \param data the data to add in the dict
- * \param free_ctn function to call with (\a key as argument) when
- * \a key is removed from the dictionary
+ * \param free_ctn function to call with (\a data as argument) when
+ * \a data is removed from the dictionary
*
* 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 in \a key_len.
*
* 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 in \a key_len.
- DEBUG5("ADD %.*s hash = %d, size = %d, & = %d", key_len, key, hash_code,
+ XBT_DEBUG("ADD %.*s hash = %d, size = %d, & = %d", key_len, key, hash_code,
dict->table_size, hash_code & dict->table_size);
current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
dict->table_size, hash_code & dict->table_size);
current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
key_len, (char *) current->content,
key_len, (char *) data, key_len, (char *) key);
/* there is already an element with the same key: overwrite it */
key_len, (char *) current->content,
key_len, (char *) data, key_len, (char *) key);
/* there is already an element with the same key: overwrite it */
- * \param free_ctn function to call with (\a key as argument) when
- * \a key is removed from the dictionary
+ * \param free_ctn function to call with (\a data as argument) when
+ * \a data is removed from the dictionary
*
* set the \a data in the structure under the \a key, which is a
* null terminated string.
*
* set the \a data in the structure under the \a key, which is a
* null terminated string.
- THROW2(not_found_error, 0, "key %.*s not found", key_len, key);
+ THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
- THROW1(not_found_error, 0, "key %s not found", key);
+ THROWF(not_found_error, 0, "key %s not found", key);
- THROW2(not_found_error, 0, "key %.*s not found", key_len, key);
+ THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
* \brief Add data to the dict (arbitrary key)
* \param dict the container
* \param key the key to set the new data
* \brief Add data to the dict (arbitrary key)
* \param dict the container
* \param key the key to set the new data
- * 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 in \a key_len.
+ * Set the \a data in the structure under the \a key.
+ * Both \a data and \a key are considered as uintptr_t.
*/
XBT_INLINE void xbt_dicti_set(xbt_dict_t dict,
uintptr_t key, uintptr_t data)
*/
XBT_INLINE void xbt_dicti_set(xbt_dict_t dict,
uintptr_t key, uintptr_t data)
- DEBUG5("ADD %zu->%zu; hash = %d, size = %d, & = %d", key, data,
+ XBT_DEBUG("ADD %zu->%zu; hash = %d, size = %d, & = %d", key, data,
hash_code, dict->table_size, hash_code & dict->table_size);
current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
(hash_code != current->hash_code
|| sizeof(uintptr_t) != current->key_len
|| (((uintptr_t) key) != ((uintptr_t) current->key)))) {
hash_code, dict->table_size, hash_code & dict->table_size);
current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
(hash_code != current->hash_code
|| sizeof(uintptr_t) != current->key_len
|| (((uintptr_t) key) != ((uintptr_t) current->key)))) {
- THROW1(not_found_error, 0, "key %zu not found", key);
+ THROWF(not_found_error, 0, "key %zu not found", key);
PRINTF_STR(key));
xbt_dict_set(head, key, data, &free);
PRINTF_STR(key));
xbt_dict_set(head, key, data, &free);
xbt_dict_remove(head, key);
/* xbt_dict_dump(head,(void (*)(void*))&printf); */
}
xbt_dict_remove(head, key);
/* xbt_dict_dump(head,(void (*)(void*))&printf); */
}
xbt_dict_foreach(head, cursor, key, data) {
if (!key || !data || strcmp(key, data)) {
xbt_dict_foreach(head, cursor, key, data) {
if (!key || !data || strcmp(key, data)) {
- xbt_test_log3("Seen #%d: %s->%s", ++i, PRINTF_STR(key),
+ xbt_test_log("Seen #%d: %s->%s", ++i, PRINTF_STR(key),
"Found something which shouldn't be there (%s)", data);
} CATCH(e) {
if (e.category != not_found_error)
"Found something which shouldn't be there (%s)", data);
} CATCH(e) {
if (e.category != not_found_error)
- xbt_test_add1("Count elements (expecting %d)", length);
- xbt_test_assert2(xbt_dict_length(dict) == length,
+ xbt_test_add("Count elements (expecting %d)", length);
+ xbt_test_assert(xbt_dict_length(dict) == length,
"Announced length(%d) != %d.", xbt_dict_length(dict),
length);
xbt_dict_foreach(dict, cursor, key, data)
effective++;
"Announced length(%d) != %d.", xbt_dict_length(dict),
length);
xbt_dict_foreach(dict, cursor, key, data)
effective++;
"Announced length(%d) != %d.", xbt_dict_length(dict),
length);
xbt_dict_foreach(dict, cursor, key, data) {
effective++;
key2 = xbt_dict_get_key(dict, data);
"Announced length(%d) != %d.", xbt_dict_length(dict),
length);
xbt_dict_foreach(dict, cursor, key, data) {
effective++;
key2 = xbt_dict_get_key(dict, data);
XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse")
{
XBT_TEST_UNIT("basic", test_dict_basic, "Basic usage: change, retrieve, traverse")
{
xbt_dict_set(head, "123", strdup("Changed 123"), &free);
count_check_get_key(head, 7);
xbt_dict_set(head, "123", strdup("Changed 123"), &free);
count_check_get_key(head, 7);
xbt_dict_set(head, "123", strdup("123"), &free);
count_check_get_key(head, 7);
xbt_dict_set(head, "123", strdup("123"), &free);
count_check_get_key(head, 7);
xbt_dict_set(head, "12a", strdup("Dummy 12a"), &free);
count_check_get_key(head, 7);
xbt_dict_set(head, "12a", strdup("Dummy 12a"), &free);
count_check_get_key(head, 7);
xbt_dict_set(head, "12a", strdup("12a"), &free);
count_check_get_key(head, 7);
xbt_dict_set(head, "12a", strdup("12a"), &free);
count_check_get_key(head, 7);
data = xbt_dict_get(head, "123");
xbt_test_assert(data);
xbt_test_assert(!strcmp("123", data));
data = xbt_dict_get(head, "123");
xbt_test_assert(data);
xbt_test_assert(!strcmp("123", data));
("Remove each data manually (traversing the resulting dictionary each time)");
fill(&head);
debuged_remove(head, "12a");
("Remove each data manually (traversing the resulting dictionary each time)");
fill(&head);
debuged_remove(head, "12a");
xbt_dict_set(head, "null", NULL, NULL);
search_ext(head, "null", NULL);
xbt_dict_set(head, "null", NULL, NULL);
search_ext(head, "null", NULL);
xbt_dict_foreach(head, cursor, key, data) {
if (!key || !data || strcmp(key, data)) {
xbt_dict_foreach(head, cursor, key, data) {
if (!key || !data || strcmp(key, data)) {
static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data)
{
uintptr_t stored_data = 0;
static void debuged_addi(xbt_dict_t head, uintptr_t key, uintptr_t data)
{
uintptr_t stored_data = 0;
xbt_dicti_set(head, key, data);
if (XBT_LOG_ISENABLED(xbt_dict, xbt_log_priority_debug)) {
xbt_dicti_set(head, key, data);
if (XBT_LOG_ISENABLED(xbt_dict, xbt_log_priority_debug)) {
"Retrieved data (%zu) is not what I just stored (%zu) under key %zu",
stored_data, data, key);
}
XBT_TEST_UNIT("dicti", test_dict_scalar, "Scalar data and key management")
{
"Retrieved data (%zu) is not what I just stored (%zu) under key %zu",
stored_data, data, key);
}
XBT_TEST_UNIT("dicti", test_dict_scalar, "Scalar data and key management")
{
("using 1000 elements with %d chars long randomized keys.",
SIZEOFKEY);
head = xbt_dict_new();
/* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */
("using 1000 elements with %d chars long randomized keys.",
SIZEOFKEY);
head = xbt_dict_new();
/* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */
xbt_dict_set(head, key, key, &free);
data = xbt_dict_get(head, key);
xbt_dict_set(head, key, key, &free);
data = xbt_dict_get(head, key);
key = xbt_malloc(10);
for (i = 0; i < 20; i++) {
/* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */
key = xbt_malloc(10);
for (i = 0; i < 20; i++) {
/* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */
"with get, key=%s != data=%s", key, (char *) data);
data = xbt_dict_get_ext(head, key, strlen(key));
"with get, key=%s != data=%s", key, (char *) data);
data = xbt_dict_get_ext(head, key, strlen(key));
"with get_ext, key=%s != data=%s", key,
(char *) data);
}
}
free(key);
"with get_ext, key=%s != data=%s", key,
(char *) data);
}
}
free(key);
(" Fill the struct and frees it %d times, using %d elements, "
"depth of multicache=%d, key size=%d", NB_TEST, NB_ELM, DEPTH,
KEY_SIZE);
(" Fill the struct and frees it %d times, using %d elements, "
"depth of multicache=%d, key size=%d", NB_TEST, NB_ELM, DEPTH,
KEY_SIZE);